summaryrefslogtreecommitdiffstats
path: root/libglusterfs
diff options
context:
space:
mode:
authorVikas Gorur <vikas@gluster.com>2009-09-17 05:56:25 +0000
committerAnand V. Avati <avati@dev.gluster.com>2009-09-22 06:13:32 -0700
commitfaf97734112ebe11d8a411351d9f23b528b9d616 (patch)
treed8b898e842c1be3c3b760d41188f7a4b0078232b /libglusterfs
parent239d2cbdb0a4c32df9f21de8385e2c466b934178 (diff)
libglusterfs: Add RCHECKSUM fop.
rchecksum (fd, offset, len): Calculates both the weak and strong checksums for a block of {len} bytes at {offset} in {fd}. Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
Diffstat (limited to 'libglusterfs')
-rw-r--r--libglusterfs/src/call-stub.c110
-rw-r--r--libglusterfs/src/call-stub.h28
-rw-r--r--libglusterfs/src/common-utils.c1
-rw-r--r--libglusterfs/src/defaults.c33
-rw-r--r--libglusterfs/src/defaults.h4
-rw-r--r--libglusterfs/src/glusterfs.h3
-rw-r--r--libglusterfs/src/protocol.h11
-rw-r--r--libglusterfs/src/xlator.c1
-rw-r--r--libglusterfs/src/xlator.h15
9 files changed, 204 insertions, 2 deletions
diff --git a/libglusterfs/src/call-stub.c b/libglusterfs/src/call-stub.c
index 05f58a700..701ee8872 100644
--- a/libglusterfs/src/call-stub.c
+++ b/libglusterfs/src/call-stub.c
@@ -22,6 +22,9 @@
#include "config.h"
#endif
+#include <inttypes.h>
+
+#include "md5.h"
#include "call-stub.h"
@@ -2084,6 +2087,61 @@ out:
call_stub_t *
+fop_rchecksum_stub (call_frame_t *frame,
+ fop_rchecksum_t fn,
+ fd_t *fd, off_t offset,
+ int32_t len)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+ GF_VALIDATE_OR_GOTO ("call-stub", fd, out);
+
+ stub = stub_new (frame, 1, GF_FOP_RCHECKSUM);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.rchecksum.fn = fn;
+ stub->args.rchecksum.fd = fd_ref (fd);
+ stub->args.rchecksum.offset = offset;
+ stub->args.rchecksum.len = len;
+out:
+ return stub;
+}
+
+
+call_stub_t *
+fop_rchecksum_cbk_stub (call_frame_t *frame,
+ fop_rchecksum_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ uint32_t weak_checksum,
+ uint8_t *strong_checksum)
+{
+ call_stub_t *stub = NULL;
+
+ GF_VALIDATE_OR_GOTO ("call-stub", frame, out);
+
+ stub = stub_new (frame, 0, GF_FOP_RCHECKSUM);
+ GF_VALIDATE_OR_GOTO ("call-stub", stub, out);
+
+ stub->args.rchecksum_cbk.fn = fn;
+ stub->args.rchecksum_cbk.op_ret = op_ret;
+ stub->args.rchecksum_cbk.op_errno = op_errno;
+
+ if (op_ret >= 0)
+ {
+ stub->args.rchecksum_cbk.weak_checksum =
+ weak_checksum;
+
+ stub->args.rchecksum_cbk.strong_checksum =
+ memdup (strong_checksum, MD5_DIGEST_LEN);
+ }
+out:
+ return stub;
+}
+
+
+call_stub_t *
fop_xattrop_cbk_stub (call_frame_t *frame,
fop_xattrop_cbk_t fn,
int32_t op_ret,
@@ -2656,6 +2714,17 @@ call_resume_wind (call_stub_t *stub)
stub->args.checksum.flags);
break;
}
+
+ case GF_FOP_RCHECKSUM:
+ {
+ stub->args.rchecksum.fn (stub->frame,
+ stub->frame->this,
+ stub->args.rchecksum.fd,
+ stub->args.rchecksum.offset,
+ stub->args.rchecksum.len);
+ break;
+ }
+
case GF_FOP_READDIR:
{
stub->args.readdir.fn (stub->frame,
@@ -3452,6 +3521,30 @@ call_resume_unwind (call_stub_t *stub)
break;
}
+ case GF_FOP_RCHECKSUM:
+ {
+ if (!stub->args.rchecksum_cbk.fn)
+ STACK_UNWIND (stub->frame,
+ stub->args.rchecksum_cbk.op_ret,
+ stub->args.rchecksum_cbk.op_errno,
+ stub->args.rchecksum_cbk.weak_checksum,
+ stub->args.rchecksum_cbk.strong_checksum);
+ else
+ stub->args.rchecksum_cbk.fn (stub->frame,
+ stub->frame->cookie,
+ stub->frame->this,
+ stub->args.rchecksum_cbk.op_ret,
+ stub->args.rchecksum_cbk.op_errno,
+ stub->args.rchecksum_cbk.weak_checksum,
+ stub->args.rchecksum_cbk.strong_checksum);
+ if (stub->args.rchecksum_cbk.op_ret >= 0)
+ {
+ FREE (stub->args.rchecksum_cbk.strong_checksum);
+ }
+
+ break;
+ }
+
case GF_FOP_READDIR:
{
if (!stub->args.readdir_cbk.fn)
@@ -3855,7 +3948,14 @@ call_stub_destroy_wind (call_stub_t *stub)
loc_wipe (&stub->args.checksum.loc);
break;
}
- break;
+
+ case GF_FOP_RCHECKSUM:
+ {
+ if (stub->args.rchecksum.fd)
+ fd_unref (stub->args.rchecksum.fd);
+ break;
+ }
+
case GF_FOP_READDIR:
{
if (stub->args.readdir.fd)
@@ -4105,6 +4205,14 @@ call_stub_destroy_unwind (call_stub_t *stub)
}
break;
+ case GF_FOP_RCHECKSUM:
+ {
+ if (stub->args.rchecksum_cbk.op_ret >= 0) {
+ FREE (stub->args.rchecksum_cbk.strong_checksum);
+ }
+ }
+ break;
+
case GF_FOP_READDIR:
{
if (stub->args.readdir_cbk.op_ret > 0) {
diff --git a/libglusterfs/src/call-stub.h b/libglusterfs/src/call-stub.h
index 4a8db9c5f..07bc92c31 100644
--- a/libglusterfs/src/call-stub.h
+++ b/libglusterfs/src/call-stub.h
@@ -568,6 +568,20 @@ typedef struct {
uint8_t *dir_checksum;
} checksum_cbk;
+ /* rchecksum */
+ struct {
+ fop_rchecksum_t fn;
+ fd_t *fd;
+ off_t offset;
+ int32_t len;
+ } rchecksum;
+ struct {
+ fop_rchecksum_cbk_t fn;
+ int32_t op_ret, op_errno;
+ uint32_t weak_checksum;
+ uint8_t *strong_checksum;
+ } rchecksum_cbk;
+
/* xattrop */
struct {
fop_xattrop_t fn;
@@ -1155,6 +1169,20 @@ fop_checksum_cbk_stub (call_frame_t *frame,
uint8_t *dir_checksum);
call_stub_t *
+fop_rchecksum_stub (call_frame_t *frame,
+ fop_rchecksum_t fn,
+ fd_t *fd, off_t offset,
+ int32_t len);
+
+call_stub_t *
+fop_rchecksum_cbk_stub (call_frame_t *frame,
+ fop_rchecksum_cbk_t fn,
+ int32_t op_ret,
+ int32_t op_errno,
+ uint32_t weak_checksum,
+ uint8_t *strong_checksum);
+
+call_stub_t *
fop_xattrop_stub (call_frame_t *frame,
fop_xattrop_t fn,
loc_t *loc,
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c
index 17ac79840..2f0dec9b4 100644
--- a/libglusterfs/src/common-utils.c
+++ b/libglusterfs/src/common-utils.c
@@ -216,6 +216,7 @@ gf_global_variable_init()
gf_fop_list[GF_FOP_LOCK_FNOTIFY]= "LOCK_FNOTIFY";
gf_fop_list[GF_FOP_FSETXATTR] = "FSETXATTR";
gf_fop_list[GF_FOP_FGETXATTR] = "FGETXATTR";
+ gf_fop_list[GF_FOP_RCHECKSUM] = "RCHECKSUM";
gf_mop_list[GF_MOP_SETVOLUME] = "SETVOLUME"; /* 0 */
gf_mop_list[GF_MOP_GETVOLUME] = "GETVOLUME"; /* 1 */
diff --git a/libglusterfs/src/defaults.c b/libglusterfs/src/defaults.c
index ef8104e59..e48fd3151 100644
--- a/libglusterfs/src/defaults.c
+++ b/libglusterfs/src/defaults.c
@@ -1403,6 +1403,39 @@ default_checksum (call_frame_t *frame,
}
+static int32_t
+default_rchecksum_cbk (call_frame_t *frame,
+ void *cookie,
+ xlator_t *this,
+ int32_t op_ret,
+ int32_t op_errno,
+ uint32_t weak_checksum,
+ uint8_t *strong_checksum)
+{
+ STACK_UNWIND (frame,
+ op_ret,
+ op_errno,
+ weak_checksum,
+ strong_checksum);
+ return 0;
+}
+
+
+int32_t
+default_rchecksum (call_frame_t *frame,
+ xlator_t *this,
+ fd_t *fd, off_t offset,
+ int32_t len)
+{
+ STACK_WIND (frame,
+ default_rchecksum_cbk,
+ FIRST_CHILD(this),
+ FIRST_CHILD(this)->fops->rchecksum,
+ fd, offset, len);
+ return 0;
+}
+
+
int32_t
default_readdir_cbk (call_frame_t *frame,
void *cookie,
diff --git a/libglusterfs/src/defaults.h b/libglusterfs/src/defaults.h
index 33d974520..7b3b2cf58 100644
--- a/libglusterfs/src/defaults.h
+++ b/libglusterfs/src/defaults.h
@@ -52,6 +52,10 @@ int32_t default_checksum (call_frame_t *frame,
loc_t *loc,
int32_t flag);
+int32_t default_rchecksum (call_frame_t *frame,
+ xlator_t *this,
+ fd_t *fd, off_t offset,
+ int32_t len);
/* FileSystem operations */
int32_t default_lookup (call_frame_t *frame,
diff --git a/libglusterfs/src/glusterfs.h b/libglusterfs/src/glusterfs.h
index e522c3176..df21d40a5 100644
--- a/libglusterfs/src/glusterfs.h
+++ b/libglusterfs/src/glusterfs.h
@@ -122,7 +122,8 @@ typedef enum {
GF_FOP_LOCK_NOTIFY,
GF_FOP_LOCK_FNOTIFY,
GF_FOP_FGETXATTR,
- GF_FOP_FSETXATTR,
+ GF_FOP_FSETXATTR, /* 45 */
+ GF_FOP_RCHECKSUM,
GF_FOP_MAXVALUE,
} glusterfs_fop_t;
diff --git a/libglusterfs/src/protocol.h b/libglusterfs/src/protocol.h
index f03759f37..c0fee420e 100644
--- a/libglusterfs/src/protocol.h
+++ b/libglusterfs/src/protocol.h
@@ -797,6 +797,17 @@ typedef struct {
typedef struct {
+ int64_t fd;
+ uint64_t offset;
+ uint32_t len;
+} __attribute__((packed)) gf_fop_rchecksum_req_t;
+typedef struct {
+ uint32_t weak_checksum;
+ unsigned char strong_checksum[0];
+} __attribute__((packed)) gf_fop_rchecksum_rsp_t;
+
+
+typedef struct {
uint64_t ino;
int32_t timeout;
} __attribute__((packed)) gf_fop_lock_notify_req_t;
diff --git a/libglusterfs/src/xlator.c b/libglusterfs/src/xlator.c
index def1ad1df..5d677ac18 100644
--- a/libglusterfs/src/xlator.c
+++ b/libglusterfs/src/xlator.c
@@ -97,6 +97,7 @@ fill_defaults (xlator_t *xl)
SET_DEFAULT_FOP (setdents);
SET_DEFAULT_FOP (getdents);
SET_DEFAULT_FOP (checksum);
+ SET_DEFAULT_FOP (rchecksum);
SET_DEFAULT_FOP (xattrop);
SET_DEFAULT_FOP (fxattrop);
SET_DEFAULT_FOP (lock_notify);
diff --git a/libglusterfs/src/xlator.h b/libglusterfs/src/xlator.h
index 4adbec2e5..ff6768035 100644
--- a/libglusterfs/src/xlator.h
+++ b/libglusterfs/src/xlator.h
@@ -110,6 +110,14 @@ typedef int32_t (*fop_checksum_cbk_t) (call_frame_t *frame,
uint8_t *file_checksum,
uint8_t *dir_checksum);
+typedef int32_t (*fop_rchecksum_cbk_t) (call_frame_t *frame,
+ void *cookie,
+ xlator_t *this,
+ int32_t op_ret,
+ int32_t op_errno,
+ uint32_t weak_checksum,
+ uint8_t *strong_checksum);
+
typedef int32_t (*mop_setvolume_t) (call_frame_t *frame,
xlator_t *this,
const char *volume);
@@ -132,6 +140,11 @@ typedef int32_t (*fop_checksum_t) (call_frame_t *frame,
loc_t *loc,
int32_t flag);
+typedef int32_t (*fop_rchecksum_t) (call_frame_t *frame,
+ xlator_t *this,
+ fd_t *fd, off_t offset,
+ int32_t len);
+
struct xlator_mops {
mop_stats_t stats;
mop_getspec_t getspec;
@@ -740,6 +753,7 @@ struct xlator_fops {
fop_setdents_t setdents;
fop_getdents_t getdents;
fop_checksum_t checksum;
+ fop_rchecksum_t rchecksum;
fop_xattrop_t xattrop;
fop_fxattrop_t fxattrop;
fop_lock_notify_t lock_notify;
@@ -788,6 +802,7 @@ struct xlator_fops {
fop_setdents_cbk_t setdents_cbk;
fop_getdents_cbk_t getdents_cbk;
fop_checksum_cbk_t checksum_cbk;
+ fop_rchecksum_cbk_t rchecksum_cbk;
fop_xattrop_cbk_t xattrop_cbk;
fop_fxattrop_cbk_t fxattrop_cbk;
fop_lock_notify_cbk_t lock_notify_cbk;