Liu Yuan | 3 Nov 16:09 2012
Picon

[RFC PATCH 1/3] store/plain: move flag operation into get_open_flags()

From: Liu Yuan <tailai.ly@...>

Signed-off-by: Liu Yuan <tailai.ly@...>
---
 sheep/plain_store.c |   20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/sheep/plain_store.c b/sheep/plain_store.c
index 9ff2fc3..908f761 100644
--- a/sheep/plain_store.c
+++ b/sheep/plain_store.c
 <at>  <at>  -20,10 +20,13  <at>  <at> 

 static char stale_dir[PATH_MAX];

-static int get_open_flags(uint64_t oid, bool create)
+static int get_open_flags(uint64_t oid, bool create, int fl)
 {
 	int flags = O_DSYNC | O_RDWR;

+	if (fl & SD_FLAG_CMD_CACHE && is_disk_cache_enabled())
+		flags &= ~O_DSYNC;
+
 	if (is_data_obj(oid))
 		flags |= O_DIRECT;

 <at>  <at>  -129,7 +132,8  <at>  <at>  static int err_to_sderr(uint64_t oid, int err)

 int default_write(uint64_t oid, const struct siocb *iocb)
 {
-	int flags = get_open_flags(oid, false), fd, ret = SD_RES_SUCCESS;
+	int flags = get_open_flags(oid, false, iocb->flags), fd,
+	    ret = SD_RES_SUCCESS;
 	char path[PATH_MAX];
 	ssize_t size;

 <at>  <at>  -139,8 +143,6  <at>  <at>  int default_write(uint64_t oid, const struct siocb *iocb)
 	}

 	get_obj_path(oid, path);
-	if (iocb->flags & SD_FLAG_CMD_CACHE && is_disk_cache_enabled())
-		flags &= ~O_DSYNC;
 	fd = open(path, flags, def_fmode);
 	if (fd < 0)
 		return err_to_sderr(oid, errno);
 <at>  <at>  -172,7 +174,7  <at>  <at>  int default_cleanup(void)
 static int init_vdi_copy_number(uint64_t oid)
 {
 	char path[PATH_MAX];
-	int fd, flags = get_open_flags(oid, false), ret;
+	int fd, flags = get_open_flags(oid, false, 0), ret;
 	struct sheepdog_inode *inode = xzalloc(sizeof(*inode));

 	snprintf(path, sizeof(path), "%s%016" PRIx64, obj_path, oid);
 <at>  <at>  -233,7 +235,8  <at>  <at>  int default_init(const char *p)
 static int default_read_from_path(uint64_t oid, const char *path,
 				  const struct siocb *iocb)
 {
-	int flags = get_open_flags(oid, false), fd, ret = SD_RES_SUCCESS;
+	int flags = get_open_flags(oid, false, iocb->flags), fd,
+	    ret = SD_RES_SUCCESS;
 	ssize_t size;

 	fd = open(path, flags);
 <at>  <at>  -295,16 +298,13  <at>  <at>  int prealloc(int fd, uint32_t size)
 int default_create_and_write(uint64_t oid, const struct siocb *iocb)
 {
 	char path[PATH_MAX], tmp_path[PATH_MAX];
-	int flags = get_open_flags(oid, true);
+	int flags = get_open_flags(oid, true, iocb->flags);
 	int ret, fd;
 	uint32_t len = iocb->length;

 	get_obj_path(oid, path);
 	get_tmp_obj_path(oid, tmp_path);

-	if (iocb->flags & SD_FLAG_CMD_CACHE && is_disk_cache_enabled())
-		flags &= ~O_DSYNC;
-
 	fd = open(tmp_path, flags, def_fmode);
 	if (fd < 0) {
 		if (errno == EEXIST) {
--

-- 
1.7.9.5


Gmane