From: Jeff Layton Date: Tue, 23 Oct 2018 18:20:25 +0000 (-0400) Subject: client: add new routine to get fscid from a ceph_mount X-Git-Tag: v14.1.0~1020^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=4508a4de48d46c3e4204853bb7e4b30aeb3bae66;p=ceph.git client: add new routine to get fscid from a ceph_mount Ceph recently gained the ability to create alternate named filesystems within a cluster. We want to allow nfs-ganesha to export them, but it currently generates filehandles using a inode number+snapid tuple, and that will not be unique across multiple filesystems. Add a new field to hold the fscid in the Client, as that is generated on a per-filesystem basis via monotonic counter. When we mount, fetch the fscid and store it in that field. Add a new Client accessor, and a libcephfs function that returns that value. Tracker: http://tracker.ceph.com/issues/36585 Signed-off-by: Jeff Layton --- diff --git a/src/client/Client.cc b/src/client/Client.cc index 86cde92945a2..c2bad5efbccf 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -243,7 +243,8 @@ Client::Client(Messenger *m, MonClient *mc, Objecter *objecter_) interrupt_finisher(m->cct), remount_finisher(m->cct), objecter_finisher(m->cct), - m_command_hook(this) + m_command_hook(this), + fscid(0) { _reset_faked_inos(); @@ -5741,13 +5742,13 @@ int Client::subscribe_mdsmap(const std::string &fs_name) r = fetch_fsmap(true); if (r < 0) return r; - fs_cluster_id_t cid = fsmap_user->get_fs_cid(resolved_fs_name); - if (cid == FS_CLUSTER_ID_NONE) { + fscid = fsmap_user->get_fs_cid(resolved_fs_name); + if (fscid == FS_CLUSTER_ID_NONE) { return -ENOENT; } std::ostringstream oss; - oss << want << "." << cid; + oss << want << "." << fscid; want = oss.str(); } ldout(cct, 10) << "Subscribing to map '" << want << "'" << dendl; diff --git a/src/client/Client.h b/src/client/Client.h index 80836753ac63..82890a811ec3 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -303,6 +303,10 @@ public: const std::string& fs_name); void finish_reclaim(); + fs_cluster_id_t get_fs_cid() { + return fscid; + } + int mds_command( const std::string &mds_spec, const std::vector& cmd, @@ -1238,6 +1242,9 @@ private: bool _use_faked_inos; + // Cluster fsid + fs_cluster_id_t fscid; + // file handles, etc. interval_set free_fd_set; // unused fds ceph::unordered_map fd_map; diff --git a/src/include/cephfs/libcephfs.h b/src/include/cephfs/libcephfs.h index 31e319509737..dbb84a1e2d2c 100644 --- a/src/include/cephfs/libcephfs.h +++ b/src/include/cephfs/libcephfs.h @@ -278,6 +278,15 @@ int ceph_select_filesystem(struct ceph_mount_info *cmount, const char *fs_name); */ int ceph_mount(struct ceph_mount_info *cmount, const char *root); +/** + * Return cluster ID for a mounted ceph filesystem + * + * Every ceph filesystem has a filesystem ID associated with it. This + * function returns that value. If the ceph_mount_info does not refer to a + * mounted filesystem, this returns a negative error code. + */ +int64_t ceph_get_fs_cid(struct ceph_mount_info *cmount); + /** * Execute a management command remotely on an MDS. * diff --git a/src/libcephfs.cc b/src/libcephfs.cc index 0d8ad43f9f58..38f9fc7ddd51 100644 --- a/src/libcephfs.cc +++ b/src/libcephfs.cc @@ -538,6 +538,13 @@ extern "C" struct UserPerm *ceph_mount_perms(struct ceph_mount_info *cmount) return &cmount->default_perms; } +extern "C" int64_t ceph_get_fs_cid(struct ceph_mount_info *cmount) +{ + if (!cmount->is_mounted()) + return -ENOTCONN; + return cmount->get_client()->get_fs_cid(); +} + extern "C" int ceph_mount_perms_set(struct ceph_mount_info *cmount, struct UserPerm *perms) {