summaryrefslogtreecommitdiffstats
path: root/libglusterfs
diff options
context:
space:
mode:
Diffstat (limited to 'libglusterfs')
-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))