From 45707a5ae95a9154a57fb7bf56f7cd64e2c40896 Mon Sep 17 00:00:00 2001 From: Vikas Gorur Date: Thu, 17 Sep 2009 05:56:26 +0000 Subject: storage/posix: Implement rchecksum. Signed-off-by: Anand V. Avati --- xlators/storage/posix/src/posix.c | 66 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'xlators/storage') 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, }; -- cgit