]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
client, libcephfs: Add fcopyfile bindings
authorChristopher Hoffman <choffman@redhat.com>
Fri, 16 May 2025 13:19:25 +0000 (13:19 +0000)
committerChristopher Hoffman <choffman@redhat.com>
Wed, 5 Nov 2025 13:59:35 +0000 (13:59 +0000)
Signed-off-by: Christopher Hoffman <choffman@redhat.com>
src/client/Client.cc
src/client/Client.h
src/include/cephfs/libcephfs.h
src/libcephfs.cc
src/pybind/cephfs/c_cephfs.pxd
src/pybind/cephfs/cephfs.pyx

index f5aec9e2254f4464363f61ebd1e3e5c23cc70f59..2b323cfa6d2b2a599d2deab82387022c225867ca 100644 (file)
@@ -18803,6 +18803,10 @@ int Client::get_inode_flags(int fd, int* file_attr_out) {
   return get_inode_flags(fh->inode.get(), file_attr_out);
 }
 
+int Client::fcopyfile(const char *spath, const char *dpath, UserPerm& perms, mode_t mode) {
+ return 0;
+}
+
 StandaloneClient::StandaloneClient(Messenger *m, MonClient *mc,
                                   boost::asio::io_context& ictx)
   : Client(m, mc, new Objecter(m->cct, m, mc, ictx))
index c89fbeb51739079d341ab96a08f1f2144cd87516..b93b0784101504c7d7e9863aa05835bd4b5646b9 100644 (file)
@@ -387,6 +387,8 @@ public:
   int get_inode_flags(const Inode* in, int* file_attr_out);
   int get_inode_flags(int fd, int* file_attr_out);
 
+  int fcopyfile(const char *sname, const char *dname, UserPerm& perms, mode_t mode);
+
   int set_fscrypt_policy_v2(int fd, const struct fscrypt_policy_v2& policy);
   int is_encrypted(int fd, UserPerm& perms, char* enctag);
 
index 833385d1e503fcd450273e6e4424eadbba9ebc6c..a320bd01e2942193f7e6f9e3e6d02b1a4208adc1 100644 (file)
@@ -2393,6 +2393,7 @@ void ceph_free_snap_info_buffer(struct snap_info *snap_info);
  */
 int ceph_get_perf_counters(struct ceph_mount_info *cmount, char **perf_dump);
 
+int ceph_fcopyfile(struct ceph_mount_info *cmount, const char *spath, const char *dpath, mode_t mode);
 #ifdef __cplusplus
 }
 #endif
index 078acfdcc321dcd4c59a031d7a09543db4e446a8..386f54d673aefc8e9d4e9f5859951330d44f24f3 100644 (file)
@@ -2639,3 +2639,10 @@ extern "C" int get_inode_flags(struct ceph_mount_info *cmount, int fd, int* file
 
   return cmount->get_client()->get_inode_flags(fd, file_attr_out);
 }
+
+extern "C" int ceph_fcopyfile(struct ceph_mount_info *cmount, const char *spath, const char *dpath, mode_t mode)
+{
+  if (!cmount->is_mounted())
+    return -ENOTCONN;
+  return cmount->get_client()->fcopyfile(spath, dpath, cmount->default_perms, mode);
+}
index 141ad718667480f2407d64a334968da9314e9288..3e0370c385dcdedf56452f0193efd259dcf2fb96 100644 (file)
@@ -108,6 +108,7 @@ cdef extern from "cephfs/libcephfs.h" nogil:
     int ceph_listxattr(ceph_mount_info *cmount, const char *path, char *list, size_t size)
     int ceph_flistxattr(ceph_mount_info *cmount, int fd, char *list, size_t size)
     int ceph_llistxattr(ceph_mount_info *cmount, const char *path, char *list, size_t size)
+    int ceph_fcopyfile(ceph_mount_info *cmount, const char *spath, const char *dpath, mode_t mode)
     int ceph_write(ceph_mount_info *cmount, int fd, const char *buf, int64_t size, int64_t offset)
     int ceph_pwritev(ceph_mount_info *cmount, int fd, iovec *iov, int iovcnt, int64_t offset)
     int ceph_read(ceph_mount_info *cmount, int fd, char *buf, int64_t size, int64_t offset)
index 8f34788dc1dffecbaea18579c2f2c9ec11e83e74..52e856facabf42cc12221fc8135fd7abcd85902c 100644 (file)
@@ -1987,6 +1987,29 @@ cdef class LibCephFS(object):
 
         return self.listxattr(path, size=size, follow_symlink=False)
 
+    def fcopyfile(self, spath, dpath, mode=0):
+        """
+        Copy a file to another file.
+
+       :param spath: the path to the source file.
+       :param dpath: the path to the destination file.
+       :param mode: the permissions the file should have once created.
+       """
+        self.require_state("mounted")
+
+        spath = cstr(spath, 'spath')
+        dpath = cstr(dpath, 'dpath')
+
+        cdef:
+            char *_spath = spath
+            char *_dpath = dpath
+            mode_t _mode = mode
+
+            ret = ceph_fcopyfile(self.cluster, _spath, _dpath, _mode)
+
+        if ret < 0:
+            raise make_ex(ret, "error in fcopyfile")
+
     def stat(self, path, follow_symlink=True):
         """
         Get a file's extended statistics and attributes.