summaryrefslogtreecommitdiffstats
path: root/xlators/storage
diff options
context:
space:
mode:
authorVikas Gorur <vikas@gluster.com>2009-09-17 05:56:26 +0000
committerAnand V. Avati <avati@dev.gluster.com>2009-09-22 06:13:32 -0700
commit45707a5ae95a9154a57fb7bf56f7cd64e2c40896 (patch)
treeccf2ccb511d8344c8a021dcd3347aa344559c853 /xlators/storage
parentfaf97734112ebe11d8a411351d9f23b528b9d616 (diff)
storage/posix: Implement rchecksum.
Signed-off-by: Anand V. Avati <avati@dev.gluster.com>
Diffstat (limited to 'xlators/storage')
-rw-r--r--xlators/storage/posix/src/posix.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/xlators/storage/posix/src/posix.c b/xlators/storage/posix/src/posix.c
index 4f095d17bc9..d022e4c287f 100644
--- a/xlators/storage/posix/src/posix.c
+++ b/xlators/storage/posix/src/posix.c
@@ -36,6 +36,8 @@
#endif /* GF_BSD_HOST_OS */
#include "glusterfs.h"
+#include "md5.h"
+#include "checksum.h"
#include "dict.h"
#include "logging.h"
#include "posix.h"
@@ -4301,6 +4303,69 @@ posix_inode (xlator_t *this)
return 0;
}
+
+int32_t
+posix_rchecksum (call_frame_t *frame, xlator_t *this,
+ fd_t *fd, off_t offset, int32_t len)
+{
+ char *buf = NULL;
+
+ int _fd = -1;
+ uint64_t tmp_pfd = 0;
+
+ struct posix_fd *pfd = NULL;
+
+ int op_ret = -1;
+ int op_errno = 0;
+
+ int ret = 0;
+
+ int32_t weak_checksum = 0;
+ uint8_t strong_checksum[MD5_DIGEST_LEN];
+
+ VALIDATE_OR_GOTO (frame, out);
+ VALIDATE_OR_GOTO (this, out);
+ VALIDATE_OR_GOTO (fd, out);
+
+ buf = CALLOC (1, len);
+ if (!buf) {
+ op_errno = ENOMEM;
+ gf_log (this->name, GF_LOG_ERROR,
+ "Out of memory");
+ goto out;
+ }
+
+ ret = fd_ctx_get (fd, this, &tmp_pfd);
+ if (ret < 0) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "pfd is NULL, fd=%p", fd);
+ op_errno = -ret;
+ goto out;
+ }
+ pfd = (struct posix_fd *)(long) tmp_pfd;
+
+ _fd = pfd->fd;
+
+ ret = pread (_fd, buf, len, offset);
+ if (ret < 0) {
+ gf_log (this->name, GF_LOG_DEBUG,
+ "pread of %d bytes returned %d (%s)",
+ len, ret, strerror (errno));
+
+ op_errno = errno;
+ goto out;
+ }
+
+ weak_checksum = gf_rsync_weak_checksum (buf, len);
+ gf_rsync_strong_checksum (buf, len, strong_checksum);
+
+ op_ret = 0;
+out:
+ STACK_UNWIND (frame, op_ret, op_errno, weak_checksum, strong_checksum);
+ return 0;
+}
+
+
/**
* notify - when parent sends PARENT_UP, send CHILD_UP event from here
*/
@@ -4603,6 +4668,7 @@ struct xlator_fops fops = {
.setdents = posix_setdents,
.getdents = posix_getdents,
.checksum = posix_checksum,
+ .rchecksum = posix_rchecksum,
.xattrop = posix_xattrop,
.fxattrop = posix_fxattrop,
};