]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
client: add ceph_open_layout interface
authorNoah Watkins <noahwatkins@gmail.com>
Tue, 20 Nov 2012 21:05:47 +0000 (13:05 -0800)
committerSage Weil <sage@inktank.com>
Mon, 26 Nov 2012 19:15:47 +0000 (11:15 -0800)
Adds an interface identical to ceph_open() that takes additional
parameters specifying a file layout to use on new files.

Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
Reviewed-by: Sage Weil <sage@inktank.com>
src/client/Client.cc
src/client/Client.h
src/include/cephfs/libcephfs.h
src/libcephfs.cc
src/test/libcephfs/test.cc

index 8d4a5ac63d4d061dad78740bed3695024fabce85..641aba170d7a87d4e6e2ac7ca0550f96aa44e8db 100644 (file)
@@ -5100,7 +5100,8 @@ int Client::getdir(const char *relpath, list<string>& contents)
 
 
 /****** file i/o **********/
-int Client::open(const char *relpath, int flags, mode_t mode) 
+int Client::open(const char *relpath, int flags, mode_t mode, int stripe_unit,
+    int stripe_count, int object_size, const char *data_pool)
 {
   ldout(cct, 3) << "open enter(" << relpath << ", " << flags << "," << mode << ") = " << dendl;
   Mutex::Locker lock(client_lock);
@@ -5124,7 +5125,8 @@ int Client::open(const char *relpath, int flags, mode_t mode)
     r = path_walk(dirpath, &dir);
     if (r < 0)
       return r;
-    r = _create(dir, dname.c_str(), flags, mode, &in, &fh);
+    r = _create(dir, dname.c_str(), flags, mode, &in, &fh, stripe_unit,
+                stripe_count, object_size, data_pool);
     created = true;
   }
   if (r < 0)
@@ -5156,6 +5158,13 @@ int Client::open(const char *relpath, int flags, mode_t mode)
   return r;
 }
 
+int Client::open(const char *relpath, int flags, mode_t mode)
+{
+  /* Use default file striping parameters */
+  return open(relpath, flags, mode, file_stripe_unit, file_stripe_count,
+      object_size, NULL);
+}
+
 int Client::lookup_hash(inodeno_t ino, inodeno_t dirino, const char *name)
 {
   Mutex::Locker lock(client_lock);
@@ -6598,7 +6607,8 @@ int Client::ll_mknod(vinodeno_t parent, const char *name, mode_t mode, dev_t rde
   return r;
 }
 
-int Client::_create(Inode *dir, const char *name, int flags, mode_t mode, Inode **inp, Fh **fhp, int uid, int gid) 
+int Client::_create(Inode *dir, const char *name, int flags, mode_t mode, Inode **inp, Fh **fhp,
+    int stripe_unit, int stripe_count, int object_size, const char *data_pool, int uid, int gid)
 { 
   ldout(cct, 3) << "_create(" << dir->ino << " " << name << ", 0" << oct << mode << dec << ")" << dendl;
   
@@ -6622,8 +6632,8 @@ int Client::_create(Inode *dir, const char *name, int flags, mode_t mode, Inode
   req->head.args.open.flags = flags | O_CREAT;
   req->head.args.open.mode = mode;
   
-  req->head.args.open.stripe_unit = file_stripe_unit;
-  req->head.args.open.stripe_count = file_stripe_count;
+  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.file_replication = file_replication;
   req->dentry_drop = CEPH_CAP_FILE_SHARED;
index f6f288a5bba0f62020b0abc716fb8d58559f869c..ae75d2df9fe13a2721a2599e252a7f463c2fb99c 100644 (file)
@@ -529,7 +529,9 @@ private:
   int _setxattr(Inode *in, const char *name, const void *value, size_t len, int flags, int uid=-1, int gid=-1);
   int _removexattr(Inode *in, const char *nm, int uid=-1, int gid=-1);
   int _open(Inode *in, int flags, mode_t mode, Fh **fhp, int uid=-1, int gid=-1);
-  int _create(Inode *in, const char *name, int flags, mode_t mode, Inode **inp, Fh **fhp, int uid=-1, int gid=-1);
+  int _create(Inode *in, const char *name, int flags, mode_t mode, Inode **inp, Fh **fhp,
+      int stripe_unit, int stripe_count, int object_size, const char *data_pool,
+             int uid=-1, int gid=-1);
   loff_t _lseek(Fh *fh, loff_t offset, int whence);
   int _read(Fh *fh, int64_t offset, uint64_t size, bufferlist *bl);
   int _write(Fh *fh, int64_t offset, uint64_t size, const char *buf);
@@ -620,6 +622,7 @@ public:
   // file ops
   int mknod(const char *path, mode_t mode, dev_t rdev=0);
   int open(const char *path, int flags, mode_t mode=0);
+  int open(const char *path, int flags, mode_t mode, int stripe_unit, int stripe_count, int object_size, const char *data_pool);
   int lookup_hash(inodeno_t ino, inodeno_t dirino, const char *name);
   int lookup_ino(inodeno_t ino);
   int close(int fd);
index 3ebbac13226873b15f8ae73da665f6b002fdf71c..71bf25f6aed9eb61fab5ba3651b9f6b915ad7aad 100644 (file)
@@ -601,6 +601,25 @@ int ceph_mknod(struct ceph_mount_info *cmount, const char *path, mode_t mode, de
  */
 int ceph_open(struct ceph_mount_info *cmount, const char *path, int flags, mode_t mode);
 
+/**
+ * Create and/or open a file with a specific file layout.
+ *
+ * @param cmount the ceph mount handle to use for performing the open.
+ * @param path the path of the file to open.  If the flags parameter includes O_CREAT,
+ *        the file will first be created before opening.
+ * @param flags a set of option masks that control how the file is created/opened.
+ * @param mode the permissions to place on the file if the file does not exist and O_CREAT
+ *        is specified in the flags.
+ * @param stripe_unit the stripe unit size (option, -1 for default)
+ * @param stripe_count the stripe count (optional, -1 for default)
+ * @param object_size the object size (optional, -1 for default)
+ * @param data_pool name of target data pool name (optional, NULL or empty string for default)
+ * @returns a non-negative file descriptor number on success or a negative error code on failure.
+ */
+int ceph_open_layout(struct ceph_mount_info *cmount, const char *path, int flags,
+                    mode_t mode, int stripe_unit, int stripe_count, int object_size,
+                    const char *data_pool);
+
 /**
  * Close the open file.
  *
index f23b959c9b1a2d1a842c45715f2bee406211d2a3..02cf0864972c95549c6b26015879c976d6e0fc9c 100644 (file)
@@ -610,6 +610,15 @@ extern "C" int ceph_open(struct ceph_mount_info *cmount, const char *path,
   return cmount->get_client()->open(path, flags, mode);
 }
 
+extern "C" int ceph_open_layout(struct ceph_mount_info *cmount, const char *path, int flags,
+    mode_t mode, int stripe_unit, int stripe_count, int object_size, const char *data_pool)
+{
+  if (!cmount->is_mounted())
+    return -ENOTCONN;
+  return cmount->get_client()->open(path, flags, mode, stripe_unit,
+      stripe_count, object_size, data_pool);
+}
+
 extern "C" int ceph_close(struct ceph_mount_info *cmount, int fd)
 {
   if (!cmount->is_mounted())
index f398f4d4d2da9d038e33f7edcce368f10eeaca9f..42fb411362de38c2077384e2848d9fd8e1cc33e4 100644 (file)
@@ -149,6 +149,28 @@ TEST(LibCephFS, Mount) {
   ceph_shutdown(cmount);
 }
 
+TEST(LibCephFS, Open_layout) {
+  struct ceph_mount_info *cmount;
+  ASSERT_EQ(ceph_create(&cmount, NULL), 0);
+  ASSERT_EQ(ceph_conf_read_file(cmount, NULL), 0);
+  ASSERT_EQ(ceph_mount(cmount, NULL), 0);
+
+  /* valid layout */
+  char test_layout_file[256];
+  sprintf(test_layout_file, "test_layout_%d_b", getpid());
+  int fd = ceph_open_layout(cmount, test_layout_file, O_CREAT, 0666, (1<<20), 7, (1<<20), NULL);
+  ASSERT_GT(fd, 0);
+  ceph_close(cmount, fd);
+
+  /* invalid layout */
+  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);
+  ceph_close(cmount, fd);
+
+  ceph_shutdown(cmount);
+}
+
 TEST(LibCephFS, Dir_ls) {
 
   pid_t mypid = getpid();