]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
client: add new ceph_mount_perms_set function 20719/head
authorJeff Layton <jlayton@redhat.com>
Fri, 26 Jan 2018 20:04:04 +0000 (15:04 -0500)
committerJeff Layton <jlayton@redhat.com>
Mon, 5 Mar 2018 14:15:15 +0000 (09:15 -0500)
Allow programs to craft a UserPerm structure to use as the default
perms on the mount. The UserPerm is copied, so the caller can delete
the model UserPerm once the call is complete.

Note that we do not currently allow setting this once ceph_mount has
been called, as there are potential races that could occur while copying
it. We could eventually allow that, but we'd have to ensure that the
default_perms remain valid for accessors operating during and after the
copy.

Tracker: http://tracker.ceph.com/issues/22802
Signed-off-by: Jeff Layton <jlayton@redhat.com>
src/include/cephfs/libcephfs.h
src/libcephfs.cc
src/test/libcephfs/access.cc

index 0a48c80c9c569074a98b5c3d2d14576cb0102aa3..5cde6744fa0187f111e004a2a749c7410f0f6392 100644 (file)
@@ -164,6 +164,20 @@ void ceph_userperm_destroy(UserPerm *perm);
  */
 struct UserPerm *ceph_mount_perms(struct ceph_mount_info *cmount);
 
+/**
+ * Set cmount's default permissions
+ *
+ * @param cmount the mount info handle
+ * @param perm permissions to set to default for mount
+ *
+ * Every cmount has a default set of credentials. This does a deep copy of
+ * the given permissions to the ones in the cmount. Must be done after
+ * ceph_init but before ceph_mount.
+ *
+ * Returns 0 on success, and -EISCONN if the cmount is already mounted.
+ */
+int ceph_mount_perms_set(struct ceph_mount_info *cmount, UserPerm *perm);
+
 /**
  * @defgroup libcephfs_h_init Setup and Teardown
  * These are the first and last functions that should be called
index df687e5db3a2f9ba117a91e350329d29356e9d7f..3e92a001db58edc2217f516b6e8005bfd40ec06e 100644 (file)
@@ -462,6 +462,15 @@ extern "C" struct UserPerm *ceph_mount_perms(struct ceph_mount_info *cmount)
   return &cmount->default_perms;
 }
 
+extern "C" int ceph_mount_perms_set(struct ceph_mount_info *cmount,
+                                   struct UserPerm *perms)
+{
+  if (cmount->is_mounted())
+    return -EISCONN;
+  cmount->default_perms = *perms;
+  return 0;
+}
+
 extern "C" int ceph_statfs(struct ceph_mount_info *cmount, const char *path,
                           struct statvfs *stbuf)
 {
index ebdf499aaabb03f2149a03ae899ee67761ba78b8..b9286929acd57c734a13044c9ca4b9f934b646cc 100644 (file)
@@ -265,8 +265,13 @@ TEST(AccessTest, User) {
   ASSERT_EQ(0, ceph_conf_parse_env(cmount, NULL));
   ASSERT_EQ(0, ceph_conf_set(cmount, "key", key.c_str()));
   ASSERT_EQ(-EACCES, ceph_mount(cmount, "/"));
-  ASSERT_EQ(0, ceph_conf_set(cmount, "client_mount_uid", "123"));
-  ASSERT_EQ(0, ceph_conf_set(cmount, "client_mount_gid", "456"));
+  ASSERT_EQ(0, ceph_init(cmount));
+
+  UserPerm *perms = ceph_userperm_new(123, 456, 0, NULL);
+  ASSERT_NE(nullptr, perms);
+  ASSERT_EQ(0, ceph_mount_perms_set(cmount, perms));
+  ceph_userperm_destroy(perms);
+
   ASSERT_EQ(0, ceph_conf_set(cmount, "client_permissions", "0"));
   ASSERT_EQ(0, ceph_mount(cmount, "/"));