libceph: add CREATE osd operation support
authorYan, Zheng <zyan@redhat.com>
Thu, 13 Nov 2014 02:47:25 +0000 (10:47 +0800)
committerIlya Dryomov <idryomov@redhat.com>
Wed, 17 Dec 2014 17:09:51 +0000 (20:09 +0300)
Add CEPH_OSD_OP_CREATE support.  Also change libceph to not treat
CEPH_OSD_OP_DELETE as an extent op and add an assert to that end.

Signed-off-by: Yan, Zheng <zyan@redhat.com>
Reviewed-by: Ilya Dryomov <idryomov@redhat.com>
net/ceph/osd_client.c

index 2b0555b36e4dc21f5608180d3f660c96aab7ca84..af1b3ee195e99d7ec08120de72e07fb9d49cb11d 100644 (file)
@@ -480,8 +480,7 @@ void osd_req_op_extent_init(struct ceph_osd_request *osd_req,
        size_t payload_len = 0;
 
        BUG_ON(opcode != CEPH_OSD_OP_READ && opcode != CEPH_OSD_OP_WRITE &&
-              opcode != CEPH_OSD_OP_DELETE && opcode != CEPH_OSD_OP_ZERO &&
-              opcode != CEPH_OSD_OP_TRUNCATE);
+              opcode != CEPH_OSD_OP_ZERO && opcode != CEPH_OSD_OP_TRUNCATE);
 
        op->extent.offset = offset;
        op->extent.length = length;
@@ -663,7 +662,6 @@ static u64 osd_req_encode_op(struct ceph_osd_request *req,
        case CEPH_OSD_OP_READ:
        case CEPH_OSD_OP_WRITE:
        case CEPH_OSD_OP_ZERO:
-       case CEPH_OSD_OP_DELETE:
        case CEPH_OSD_OP_TRUNCATE:
                if (src->op == CEPH_OSD_OP_WRITE)
                        request_data_len = src->extent.length;
@@ -723,6 +721,9 @@ static u64 osd_req_encode_op(struct ceph_osd_request *req,
                ceph_osdc_msg_data_add(req->r_request, osd_data);
                request_data_len = osd_data->pagelist->length;
                break;
+       case CEPH_OSD_OP_CREATE:
+       case CEPH_OSD_OP_DELETE:
+               break;
        default:
                pr_err("unsupported osd opcode %s\n",
                        ceph_osd_op_name(src->op));
@@ -763,13 +764,11 @@ struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc,
        u64 objnum = 0;
        u64 objoff = 0;
        u64 objlen = 0;
-       u32 object_size;
-       u64 object_base;
        int r;
 
        BUG_ON(opcode != CEPH_OSD_OP_READ && opcode != CEPH_OSD_OP_WRITE &&
-              opcode != CEPH_OSD_OP_DELETE && opcode != CEPH_OSD_OP_ZERO &&
-              opcode != CEPH_OSD_OP_TRUNCATE);
+              opcode != CEPH_OSD_OP_ZERO && opcode != CEPH_OSD_OP_TRUNCATE &&
+              opcode != CEPH_OSD_OP_CREATE && opcode != CEPH_OSD_OP_DELETE);
 
        req = ceph_osdc_alloc_request(osdc, snapc, num_ops, use_mempool,
                                        GFP_NOFS);
@@ -785,21 +784,24 @@ struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc,
                return ERR_PTR(r);
        }
 
-       object_size = le32_to_cpu(layout->fl_object_size);
-       object_base = off - objoff;
-       if (!(truncate_seq == 1 && truncate_size == -1ULL)) {
-               if (truncate_size <= object_base) {
-                       truncate_size = 0;
-               } else {
-                       truncate_size -= object_base;
-                       if (truncate_size > object_size)
-                               truncate_size = object_size;
+       if (opcode == CEPH_OSD_OP_CREATE || opcode == CEPH_OSD_OP_DELETE) {
+               osd_req_op_init(req, 0, opcode);
+       } else {
+               u32 object_size = le32_to_cpu(layout->fl_object_size);
+               u32 object_base = off - objoff;
+               if (!(truncate_seq == 1 && truncate_size == -1ULL)) {
+                       if (truncate_size <= object_base) {
+                               truncate_size = 0;
+                       } else {
+                               truncate_size -= object_base;
+                               if (truncate_size > object_size)
+                                       truncate_size = object_size;
+                       }
                }
-       }
-
-       osd_req_op_extent_init(req, 0, opcode, objoff, objlen,
-                               truncate_size, truncate_seq);
 
+               osd_req_op_extent_init(req, 0, opcode, objoff, objlen,
+                                      truncate_size, truncate_seq);
+       }
        /*
         * A second op in the ops array means the caller wants to
         * also issue a include a 'startsync' command so that the