]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
client: specify data pool on create operations
authorSage Weil <sage@inktank.com>
Thu, 6 Dec 2012 08:12:17 +0000 (00:12 -0800)
committerSage Weil <sage@inktank.com>
Mon, 24 Dec 2012 03:39:22 +0000 (19:39 -0800)
Fill in the data pool field if specified by the client, or set to -1.

Signed-off-by: Sage Weil <sage@inktank.com>
src/client/Client.cc
src/test/libcephfs/test.cc

index 362099d9cec35531523d4172f36ddd1ee0559ba3..ac23877ebc0773d4787fc2907e56bbdeb4e4c234 100644 (file)
@@ -5270,6 +5270,7 @@ int Client::_open(Inode *in, int flags, mode_t mode, Fh **fhp, int uid, int gid)
     req->set_filepath(path); 
     req->head.args.open.flags = flags & ~O_CREAT;
     req->head.args.open.mode = mode;
+    req->head.args.open.pool = -1;
     req->head.args.open.old_size = in->size;   // for O_TRUNC
     req->inode = in;
     result = make_request(req, uid, gid);
@@ -6638,11 +6639,20 @@ int Client::_create(Inode *dir, const char *name, int flags, mode_t mode, Inode
   if (dir->snapid != CEPH_NOSNAP) {
     return -EROFS;
   }
-  
+
   int cmode = ceph_flags_to_mode(flags);
   if (cmode < 0)
     return -EINVAL;
 
+  int64_t pool_id = -1;
+  if (data_pool && *data_pool) {
+    pool_id = osdmap->lookup_pg_pool_name(data_pool);
+    if (pool_id < 0)
+      return -EINVAL;
+    if (pool_id > 0xffffffffll)
+      return -ERANGE;  // bummer!
+  }
+
   MetaRequest *req = new MetaRequest(CEPH_MDS_OP_CREATE);
 
   filepath path;
@@ -6656,6 +6666,7 @@ int Client::_create(Inode *dir, const char *name, int flags, mode_t mode, Inode
   req->head.args.open.stripe_unit = stripe_unit;
   req->head.args.open.stripe_count = stripe_count;
   req->head.args.open.object_size = object_size;
+  req->head.args.open.pool = pool_id;
   req->dentry_drop = CEPH_CAP_FILE_SHARED;
   req->dentry_unless = CEPH_CAP_FILE_EXCL;
 
index 67bf78c82afa245205a2a13825ee3d79194df364..b2d22f9acebb21e1b7c1883f78ab0f4b2c67d34a 100644 (file)
@@ -166,8 +166,23 @@ TEST(LibCephFS, OpenLayout) {
   sprintf(test_layout_file, "test_layout_%d_c", getpid());
   fd = ceph_open_layout(cmount, test_layout_file, O_CREAT, 0666, (1<<20), 1, 19, NULL);
   ASSERT_EQ(fd, -EINVAL);
+
+  /* with data pool */
+  sprintf(test_layout_file, "test_layout_%d_d", getpid());
+  fd = ceph_open_layout(cmount, test_layout_file, O_CREAT, 0666, (1<<20), 7, (1<<20), "data");
+  ASSERT_GT(fd, 0);
   ceph_close(cmount, fd);
 
+  /* with metadata pool (invalid) */
+  sprintf(test_layout_file, "test_layout_%d_e", getpid());
+  fd = ceph_open_layout(cmount, test_layout_file, O_CREAT, 0666, (1<<20), 7, (1<<20), "metadata");
+  ASSERT_EQ(fd, -EINVAL);
+
+  /* with metadata pool (does not exist) */
+  sprintf(test_layout_file, "test_layout_%d_f", getpid());
+  fd = ceph_open_layout(cmount, test_layout_file, O_CREAT, 0666, (1<<20), 7, (1<<20), "asdfjasdfjasdf");
+  ASSERT_EQ(fd, -EINVAL);
+
   ceph_shutdown(cmount);
 }