The SD_OP_WRITE_OBJ/SD_OP_READ_OBJ and SD_OP_CREATE_AND_WRITE_OBJ share
no code, so split them apart.  Also us O_TRUNC instead of calling
ftruncate to zero after opening for the SD_OP_CREATE_AND_WRITE_OBJ case.

Signed-off-by: Christoph Hellwig <[email protected]>

Index: sheepdog/sheep/store.c
===================================================================
--- sheepdog.orig/sheep/store.c 2011-11-10 18:58:07.657298965 +0100
+++ sheepdog/sheep/store.c      2011-11-10 19:00:20.571794759 +0100
@@ -589,31 +589,23 @@ static int store_queue_request_local(str
        dprintf("%x, %" PRIx64" , %u\n", opcode, oid, epoch);
 
        switch (opcode) {
-       case SD_OP_CREATE_AND_WRITE_OBJ:
        case SD_OP_WRITE_OBJ:
        case SD_OP_READ_OBJ:
-               if (opcode == SD_OP_CREATE_AND_WRITE_OBJ)
-                       fd = ob_open(epoch, oid, O_CREAT, &ret);
-               else
-                       fd = ob_open(epoch, oid, 0, &ret);
-
+               fd = ob_open(epoch, oid, 0, &ret);
                if (fd < 0) {
                        ret = SD_RES_EIO;
                        goto out;
                }
-
-               if (opcode != SD_OP_CREATE_AND_WRITE_OBJ)
-                       break;
-
+               break;
+       case SD_OP_CREATE_AND_WRITE_OBJ:
                if (!hdr->copies) {
                        eprintf("the number of copies cannot be zero\n");
                        ret = SD_RES_INVALID_PARMS;
                        goto out;
                }
 
-               ret = ftruncate(fd, 0);
-               if (ret) {
-                       eprintf("%m\n");
+               fd = ob_open(epoch, oid, O_CREAT|O_TRUNC, &ret);
+               if (fd < 0) {
                        ret = SD_RES_EIO;
                        goto out;
                }

-- 
sheepdog mailing list
[email protected]
http://lists.wpkg.org/mailman/listinfo/sheepdog

Reply via email to