diff mbox series

[v2,2/2] ceph: add CEPH_IOC_GET_CLUSTER_AND_CLIENT_IDS ioctl cmd support

Message ID 20201110105755.340315-3-xiubli@redhat.com
State New
Headers show
Series ceph: add _IDS ioctl cmd and status debug file support | expand

Commit Message

Xiubo Li Nov. 10, 2020, 10:57 a.m. UTC
From: Xiubo Li <xiubli@redhat.com>

This ioctl will return the cluster and client ids back to userspace.
With this we can easily know which mountpoint the file belongs to and
also they can help locate the debugfs path quickly.

URL: https://tracker.ceph.com/issues/48124
Signed-off-by: Xiubo Li <xiubli@redhat.com>
---
 fs/ceph/ioctl.c | 23 +++++++++++++++++++++++
 fs/ceph/ioctl.h | 15 +++++++++++++++
 2 files changed, 38 insertions(+)
diff mbox series

Patch

diff --git a/fs/ceph/ioctl.c b/fs/ceph/ioctl.c
index 6e061bf62ad4..a4b69c1026ce 100644
--- a/fs/ceph/ioctl.c
+++ b/fs/ceph/ioctl.c
@@ -268,6 +268,27 @@  static long ceph_ioctl_syncio(struct file *file)
 	return 0;
 }
 
+/*
+ * Return the cluster and client ids
+ */
+static long ceph_ioctl_get_fs_ids(struct file *file, void __user *arg)
+{
+	struct inode *inode = file_inode(file);
+	struct ceph_fs_client *fsc = ceph_sb_to_client(inode->i_sb);
+	struct cluster_client_ids ids;
+
+	snprintf(ids.cluster_id, sizeof(ids.cluster_id), "%pU",
+		 &fsc->client->fsid);
+	snprintf(ids.client_id, sizeof(ids.client_id), "client%lld",
+		 ceph_client_gid(fsc->client));
+
+	/* send result back to user */
+	if (copy_to_user(arg, &ids, sizeof(ids)))
+		return -EFAULT;
+
+	return 0;
+}
+
 long ceph_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 {
 	dout("ioctl file %p cmd %u arg %lu\n", file, cmd, arg);
@@ -289,6 +310,8 @@  long ceph_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
 
 	case CEPH_IOC_SYNCIO:
 		return ceph_ioctl_syncio(file);
+	case CEPH_IOC_GET_CLUSTER_AND_CLIENT_IDS:
+		return ceph_ioctl_get_fs_ids(file, (void __user *)arg);
 	}
 
 	return -ENOTTY;
diff --git a/fs/ceph/ioctl.h b/fs/ceph/ioctl.h
index 51f7f1d39a94..9879d58854fb 100644
--- a/fs/ceph/ioctl.h
+++ b/fs/ceph/ioctl.h
@@ -98,4 +98,19 @@  struct ceph_ioctl_dataloc {
  */
 #define CEPH_IOC_SYNCIO _IO(CEPH_IOCTL_MAGIC, 5)
 
+/*
+ * CEPH_IOC_GET_CLUSTER_AND_CLIENT_IDS - get the cluster and client ids
+ *
+ * This ioctl will return the cluster and client ids back to user space.
+ * With this we can easily know which mountpoint the file belongs to and
+ * also they can help locate the debugfs path quickly.
+ */
+
+struct cluster_client_ids {
+	char cluster_id[40];
+	char client_id[24];
+};
+#define CEPH_IOC_GET_CLUSTER_AND_CLIENT_IDS _IOR(CEPH_IOCTL_MAGIC, 6, \
+					struct cluster_client_ids)
+
 #endif