summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPrasanna Kumar Kalever <prasanna.kalever@redhat.com>2017-05-19 13:30:25 +0530
committerPrasanna Kumar Kalever <prasanna.kalever@redhat.com>2017-05-19 15:59:01 +0530
commit2a3d70e536a88ac2d0cef6a56c00f871afc1667b (patch)
treefaa9b3b6d2d7276e51a65f8edbb6c77bbd3bd513
parent804ce8e7b26dbf84a6f788627ee6d80fe6e10188 (diff)
gluster-block: update journal data synchronously
Also use O_SYNC while creating/truncating block file. Change-Id: Ic0bcc3f2905c438ca5b5d3e95955bbd5d95d3ef4 Signed-off-by: Prasanna Kumar Kalever <prasanna.kalever@redhat.com>
-rw-r--r--rpc/glfs-operations.c2
-rw-r--r--utils/utils.h112
2 files changed, 58 insertions, 56 deletions
diff --git a/rpc/glfs-operations.c b/rpc/glfs-operations.c
index c7d38c4..9ae8ec5 100644
--- a/rpc/glfs-operations.c
+++ b/rpc/glfs-operations.c
@@ -102,7 +102,7 @@ glusterBlockCreateEntry(struct glfs *glfs, blockCreateCli *blk, char *gbid,
}
tgfd = glfs_creat(glfs, gbid,
- O_WRONLY | O_CREAT | O_EXCL,
+ O_WRONLY | O_CREAT | O_EXCL | O_SYNC,
S_IRUSR | S_IWUSR);
if (!tgfd) {
*errCode = errno;
diff --git a/utils/utils.h b/utils/utils.h
index 8cbf128..c9f0baf 100644
--- a/utils/utils.h
+++ b/utils/utils.h
@@ -111,62 +111,64 @@
} \
} while (0)
-# define GB_METAUPDATE_OR_GOTO(lock, glfs, fname, \
- volume, ret, errMsg, label,...) \
- do { \
- char *write; \
- struct glfs_fd *tgmfd; \
- LOCK(lock); \
- ret = glfs_chdir (glfs, GB_METADIR); \
- if (ret) { \
- GB_ASPRINTF(&errMsg, "Failed to update transaction log "\
- "for %s/%s[%s]", volume, fname, strerror(errno)); \
- LOG("gfapi", GB_LOG_ERROR, "glfs_chdir(%s) on " \
- "volume %s failed[%s]", GB_METADIR, volume, \
- strerror(errno)); \
- UNLOCK(lock); \
- ret = -1; \
- goto label; \
- } \
- tgmfd = glfs_creat(glfs, fname, O_WRONLY | O_APPEND, \
- S_IRUSR | S_IWUSR); \
- if (!tgmfd) { \
- GB_ASPRINTF(&errMsg, "Failed to update transaction log "\
- "for %s/%s[%s]", volume, fname, strerror(errno)); \
- LOG("mgmt", GB_LOG_ERROR, "glfs_creat(%s): on " \
- "volume %s failed[%s]", fname, volume, \
- strerror(errno)); \
- UNLOCK(lock); \
- ret = -1; \
- goto label; \
- } \
+# define GB_METAUPDATE_OR_GOTO(lock, glfs, fname, \
+ volume, ret, errMsg, label,...) \
+ do { \
+ char *write; \
+ struct glfs_fd *tgmfd; \
+ LOCK(lock); \
+ ret = glfs_chdir (glfs, GB_METADIR); \
+ if (ret) { \
+ GB_ASPRINTF(&errMsg, "Failed to update transaction log " \
+ "for %s/%s[%s]", volume, fname, strerror(errno)); \
+ LOG("gfapi", GB_LOG_ERROR, "glfs_chdir(%s) on " \
+ "volume %s failed[%s]", GB_METADIR, volume, \
+ strerror(errno)); \
+ UNLOCK(lock); \
+ ret = -1; \
+ goto label; \
+ } \
+ tgmfd = glfs_creat(glfs, fname, \
+ O_WRONLY | O_APPEND | O_SYNC, \
+ S_IRUSR | S_IWUSR); \
+ if (!tgmfd) { \
+ GB_ASPRINTF(&errMsg, "Failed to update transaction log " \
+ "for %s/%s[%s]", volume, fname, strerror(errno)); \
+ LOG("mgmt", GB_LOG_ERROR, "glfs_creat(%s): on " \
+ "volume %s failed[%s]", fname, volume, \
+ strerror(errno)); \
+ UNLOCK(lock); \
+ ret = -1; \
+ goto label; \
+ } \
if (GB_ASPRINTF(&write, __VA_ARGS__) < 0) { \
- UNLOCK(lock); \
- ret = -1; \
- goto label; \
- } \
- if(glfs_write (tgmfd, write, strlen(write), 0) < 0) { \
- GB_ASPRINTF(&errMsg, "Failed to update transaction log "\
- "for %s/%s[%s]", volume, fname, strerror(errno)); \
- LOG("mgmt", GB_LOG_ERROR, "glfs_write(%s): on " \
- "volume %s failed[%s]", fname, volume, \
- strerror(errno)); \
- UNLOCK(lock); \
- ret = -1; \
- goto label; \
- } \
- GB_FREE(write); \
- if (tgmfd && glfs_close(tgmfd) != 0) { \
- GB_ASPRINTF(&errMsg, "Failed to update transaction log "\
- "for %s/%s[%s]", volume, fname, strerror(errno)); \
- LOG("mgmt", GB_LOG_ERROR, "glfs_close(%s): on " \
- "volume %s failed[%s]", fname, volume, \
- strerror(errno)); \
- UNLOCK(lock); \
- ret = -1; \
- goto label; \
- } \
- UNLOCK(lock); \
+ ret = -1; \
+ } \
+ if (!ret) { \
+ if(glfs_write (tgmfd, write, strlen(write), 0) < 0) { \
+ GB_ASPRINTF(&errMsg, "Failed to update transaction log "\
+ "for %s/%s[%s]", volume, fname, strerror(errno)); \
+ LOG("mgmt", GB_LOG_ERROR, "glfs_write(%s): on " \
+ "volume %s failed[%s]", fname, volume, \
+ strerror(errno)); \
+ ret = -1; \
+ } \
+ GB_FREE(write); \
+ } \
+ if (tgmfd && glfs_close(tgmfd) != 0) { \
+ GB_ASPRINTF(&errMsg, "Failed to update transaction log " \
+ "for %s/%s[%s]", volume, fname, strerror(errno)); \
+ LOG("mgmt", GB_LOG_ERROR, "glfs_close(%s): on " \
+ "volume %s failed[%s]", fname, volume, \
+ strerror(errno)); \
+ UNLOCK(lock); \
+ ret = -1; \
+ goto label; \
+ } \
+ UNLOCK(lock); \
+ if (ret) { \
+ goto label; \
+ } \
} while (0)
# define GB_METAUNLOCK(lkfd, volume, ret, errMsg) \