]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
Added ceph_flock() to libcephfs.
authorXavier Roche <roche+git@exalead.com>
Sun, 8 Feb 2015 13:48:55 +0000 (14:48 +0100)
committerXavier Roche <roche+git@exalead.com>
Sun, 8 Feb 2015 13:48:55 +0000 (14:48 +0100)
src/client/Client.cc
src/client/Client.h
src/include/cephfs/libcephfs.h
src/libcephfs.cc

index f01c963705acc37925c7d144d1953944574a315f..ca3186a408614c6638042b5ea5c03342669e328d 100644 (file)
@@ -5728,6 +5728,19 @@ int Client::lutime(const char *relpath, struct utimbuf *buf)
   return _setattr(in, &attr, CEPH_SETATTR_MTIME|CEPH_SETATTR_ATIME);
 }
 
+int Client::flock(int fd, int operation, uint64_t owner)
+{
+  Mutex::Locker lock(client_lock);
+  tout(cct) << "flock" << std::endl;
+  tout(cct) << fd << std::endl;
+  tout(cct) << operation << std::endl;
+  Fh *f = get_filehandle(fd);
+  if (!f)
+    return -EBADF;
+
+  return _flock(f, operation, owner, NULL);
+}
+
 int Client::opendir(const char *relpath, dir_result_t **dirpp) 
 {
   Mutex::Locker lock(client_lock);
index 0d4bb2cf9f5fef4c4069c818b2cb32d35f1dcd7f..d42525f11480f75ca11dd1aeb0e967a8a18003f8 100644 (file)
@@ -813,6 +813,7 @@ public:
   int lchown(const char *path, int uid, int gid);
   int utime(const char *path, struct utimbuf *buf);
   int lutime(const char *path, struct utimbuf *buf);
+  int flock(int fd, int operation, uint64_t owner);
   int truncate(const char *path, loff_t size);
 
   // file ops
index f27f879ab2b9a3849335f2ef4c408a2de85b14e4..1d7de9decf4bad5fc29ef04568272fd653d5f3b1 100644 (file)
@@ -683,6 +683,21 @@ int ceph_lchown(struct ceph_mount_info *cmount, const char *path, int uid, int g
  */
 int ceph_utime(struct ceph_mount_info *cmount, const char *path, struct utimbuf *buf);
 
+/**
+ * Apply or remove an advisory lock.
+ *
+ * @param cmount the ceph mount handle to use for performing the utime.
+ * @param fd the open file descriptor to change advisory lock.
+ * @param operation the advisory lock operation to be performed on the file
+ * descriptor among LOCK_SH (shared lock), LOCK_EX (exclusive lock),
+ * or LOCK_UN (remove lock). The LOCK_NB value can be ORed to perform a
+ * non-blocking operation.
+ * @param owner the user-supplied owner identifier
+ * @returns 0 on success or negative error code on failure.
+ */
+int ceph_flock(struct ceph_mount_info *cmount, int fd, int operation,
+              uint64_t owner);
+
 /**
  * Truncate the file to the given size.  If this operation causes the
  * file to expand, the empty bytes will be filled in with zeros.
index e3281de27348422948caa28350c69d3c30b2c5b6..852e08d72d68d4a2d00b0bca99c7fa8f79c516f3 100644 (file)
@@ -718,6 +718,14 @@ extern "C" int ceph_utime(struct ceph_mount_info *cmount, const char *path,
   return cmount->get_client()->utime(path, buf);
 }
 
+extern "C" int ceph_flock(struct ceph_mount_info *cmount, int fd, int operation,
+                         uint64_t owner)
+{
+  if (!cmount->is_mounted())
+    return -ENOTCONN;
+  return cmount->get_client()->flock(fd, operation, owner);
+}
+
 extern "C" int ceph_truncate(struct ceph_mount_info *cmount, const char *path,
                             int64_t size)
 {