summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src
diff options
context:
space:
mode:
authorAmar Tumballi <amar@gluster.com>2009-02-26 08:09:25 -0800
committerAnand V. Avati <avati@amp.gluster.com>2009-02-27 16:13:55 +0530
commit8462dd88ad3531837ebfccd17a083467faa40227 (patch)
tree694d75c75bb88bcc67a4f1893330de03be0c4793 /libglusterfs/src
parentda9664587d414ba703c46839e3a4831ad3784a19 (diff)
volumefile modification awareness to make sure there are no inconsistencies.
Complete (including feature to properly umount) in my sense. Signed-off-by: Anand V. Avati <avati@amp.gluster.com>
Diffstat (limited to 'libglusterfs/src')
-rw-r--r--libglusterfs/src/common-utils.c51
-rw-r--r--libglusterfs/src/common-utils.h2
-rw-r--r--libglusterfs/src/glusterfs.h3
3 files changed, 56 insertions, 0 deletions
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c
index 1b4106c4123..e8a7c9ab525 100644
--- a/libglusterfs/src/common-utils.c
+++ b/libglusterfs/src/common-utils.c
@@ -1388,3 +1388,54 @@ gf_unlockfd (int fd)
return fcntl (fd, F_SETLK, &fl);
}
+static void
+compute_checksum (char *buf, size_t size, uint32_t *checksum)
+{
+ int ret = -1;
+ char *checksum_buf = NULL;
+
+ checksum_buf = (char *)(checksum);
+
+ if (!(*checksum)) {
+ checksum_buf [0] = 0xba;
+ checksum_buf [1] = 0xbe;
+ checksum_buf [2] = 0xb0;
+ checksum_buf [3] = 0x0b;
+ }
+
+ for (ret = 0; ret < (size - 4); ret += 4) {
+ checksum_buf[0] ^= (buf[ret]);
+ checksum_buf[1] ^= (buf[ret + 1] << 1) ;
+ checksum_buf[2] ^= (buf[ret + 2] << 2);
+ checksum_buf[3] ^= (buf[ret + 3] << 3);
+ }
+
+ for (ret = 0; ret <= (size % 4); ret++) {
+ checksum_buf[ret] ^= (buf[(size - 4) + ret] << ret);
+ }
+
+ return;
+}
+
+#define GF_CHECKSUM_BUF_SIZE 1024
+
+int
+get_checksum_for_file (int fd, uint32_t *checksum)
+{
+ int ret = -1;
+ char buf[GF_CHECKSUM_BUF_SIZE] = {0,};
+
+ /* goto first place */
+ lseek (fd, 0L, SEEK_SET);
+ do {
+ ret = read (fd, &buf, GF_CHECKSUM_BUF_SIZE);
+ if (ret > 0)
+ compute_checksum (buf, GF_CHECKSUM_BUF_SIZE,
+ checksum);
+ } while (ret > 0);
+
+ /* set it back */
+ lseek (fd, 0L, SEEK_SET);
+
+ return ret;
+}
diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h
index f3a39226c03..b3630d478a7 100644
--- a/libglusterfs/src/common-utils.h
+++ b/libglusterfs/src/common-utils.h
@@ -310,5 +310,7 @@ int gf_string2time (const char *str, uint32_t *n);
int gf_lockfd (int fd);
int gf_unlockfd (int fd);
+int get_checksum_for_file (int fd, uint32_t *checksum);
+
#endif /* _COMMON_UTILS_H */
diff --git a/libglusterfs/src/glusterfs.h b/libglusterfs/src/glusterfs.h
index be6412f224d..d00ec48668c 100644
--- a/libglusterfs/src/glusterfs.h
+++ b/libglusterfs/src/glusterfs.h
@@ -227,6 +227,7 @@ struct _cmd_args {
/* fuse options */
int fuse_direct_io_mode_flag;
+ int volfile_check;
double fuse_entry_timeout;
double fuse_attribute_timeout;
char *volume_name;
@@ -258,6 +259,7 @@ struct _glusterfs_ctx {
void *event_pool;
pthread_mutex_t lock;
int xl_count;
+ uint32_t volfile_checksum;
};
typedef struct _glusterfs_ctx glusterfs_ctx_t;
@@ -272,6 +274,7 @@ typedef enum {
GF_EVENT_CHILD_CONNECTING,
GF_EVENT_TRANSPORT_CLEANUP,
GF_EVENT_TRANSPORT_CONNECTED,
+ GF_EVENT_VOLFILE_MODIFIED,
} glusterfs_event_t;
#define GF_MUST_CHECK __attribute__((warn_unused_result))