From 4b60f101e4b3e890b230c197a22e5e03c54c9d0e Mon Sep 17 00:00:00 2001 From: Yehuda Sadeh Date: Mon, 9 Mar 2009 17:01:31 -0700 Subject: [PATCH] kclient: add osdc data to sysfs --- src/kernel/osd_client.c | 3 ++ src/kernel/osd_client.h | 13 +++++++ src/kernel/super.h | 2 ++ src/kernel/sysfs.c | 79 +++++++++++++++++++++++++++++++++++++---- 4 files changed, 91 insertions(+), 6 deletions(-) diff --git a/src/kernel/osd_client.c b/src/kernel/osd_client.c index 1b15e2ea1d362..832632b77cb5a 100644 --- a/src/kernel/osd_client.c +++ b/src/kernel/osd_client.c @@ -194,6 +194,7 @@ static int register_request(struct ceph_osd_client *osdc, round_jiffies_relative(req->r_timeout_stamp - jiffies)); } + ceph_sysfs_osd_req_init(osdc, req); out: mutex_unlock(&osdc->request_mutex); return rc; @@ -296,6 +297,8 @@ static void __unregister_request(struct ceph_osd_client *osdc, jiffies)); } } + + ceph_sysfs_osd_req_cleanup(req); } /* diff --git a/src/kernel/osd_client.h b/src/kernel/osd_client.h index 687ec787fa6e3..0f60a9bdadb5a 100644 --- a/src/kernel/osd_client.h +++ b/src/kernel/osd_client.h @@ -32,9 +32,21 @@ struct ceph_osd_request; */ typedef void (*ceph_osdc_callback_t)(struct ceph_osd_request *); +struct ceph_osd_request_attr { + struct attribute attr; + ssize_t (*show)(struct ceph_osd_request *, struct ceph_osd_request_attr *, + char *); + ssize_t (*store)(struct ceph_osd_request *, struct ceph_osd_request_attr *, + const char *, size_t); +}; + /* an in-flight request */ struct ceph_osd_request { u64 r_tid; /* unique for this client */ + + struct kobject kobj; + struct ceph_osd_request_attr k_osd, k_op; + struct ceph_msg *r_request; struct ceph_msg *r_reply; int r_result; @@ -71,6 +83,7 @@ struct ceph_osd_client { struct radix_tree_root request_tree; /* pending requests, by tid */ int num_requests; struct delayed_work timeout_work; + struct kobject kobj; }; extern void ceph_osdc_init(struct ceph_osd_client *osdc, diff --git a/src/kernel/super.h b/src/kernel/super.h index 96389c631a372..f6b0b8d109a72 100644 --- a/src/kernel/super.h +++ b/src/kernel/super.h @@ -801,6 +801,8 @@ extern int ceph_sysfs_init(void); extern void ceph_sysfs_cleanup(void); extern int ceph_sysfs_mds_req_init(struct ceph_mds_client *mdsc, struct ceph_mds_request *req); extern void ceph_sysfs_mds_req_cleanup(struct ceph_mds_request *req); +extern int ceph_sysfs_osd_req_init(struct ceph_osd_client *osdc, struct ceph_osd_request *req); +extern void ceph_sysfs_osd_req_cleanup(struct ceph_osd_request *req); static inline struct inode *get_dentry_parent_inode(struct dentry *dentry) { diff --git a/src/kernel/sysfs.c b/src/kernel/sysfs.c index 37dda51a8aff9..d1325e08ea296 100644 --- a/src/kernel/sysfs.c +++ b/src/kernel/sysfs.c @@ -55,7 +55,8 @@ static struct kobj_type name##_ops = { \ DEF_ATTR_OP(ceph_client) - +DEF_ATTR_OP(ceph_mds_request) +DEF_ATTR_OP(ceph_osd_request) /* * per-client attributes @@ -175,6 +176,11 @@ int ceph_sysfs_client_init(struct ceph_client *client) if (ret) goto out; + ret = kobject_init_and_add(&client->osdc.kobj, &entity_ops, + &client->kobj, "osdc"); + if (ret) + goto out; + ADD_ENTITY_ATTR(client, k_fsid, "fsid", 0400, fsid_show, NULL); ADD_ENTITY_ATTR(client, k_monmap, "monmap", 0400, monmap_show, NULL); ADD_ENTITY_ATTR(client, k_mdsmap, "mdsmap", 0400, mdsmap_show, NULL); @@ -189,13 +195,12 @@ out: void ceph_sysfs_client_cleanup(struct ceph_client *client) { #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25) + kobject_del(&client->osdc.kobj); kobject_del(&client->mdsc.kobj); kobject_del(&client->kobj); #endif } -DEF_ATTR_OP(ceph_mds_request) - static ssize_t req_mds_show(struct ceph_mds_request *req, struct ceph_mds_request_attr *attr, char *buf) { @@ -204,7 +209,7 @@ static ssize_t req_mds_show(struct ceph_mds_request *req, ENTITY_NAME(req->r_request->hdr.dst.name)); } -static ssize_t req_op_show(struct ceph_mds_request *req, +static ssize_t req_mds_op_show(struct ceph_mds_request *req, struct ceph_mds_request_attr *attr, char *buf) { int pos = 0, pathlen; @@ -251,10 +256,9 @@ int ceph_sysfs_mds_req_init(struct ceph_mds_client *mdsc, struct ceph_mds_reques goto out; ADD_ENTITY_ATTR(req, k_mds, "mds", 0400, req_mds_show, NULL); - ADD_ENTITY_ATTR(req, k_op, "op", 0400, req_op_show, NULL); + ADD_ENTITY_ATTR(req, k_op, "op", 0400, req_mds_op_show, NULL); return 0; - out: #endif return ret; @@ -267,6 +271,69 @@ void ceph_sysfs_mds_req_cleanup(struct ceph_mds_request *req) #endif } +static ssize_t req_osd_show(struct ceph_osd_request *req, + struct ceph_osd_request_attr *attr, char *buf) +{ + return sprintf(buf, "%u.%u.%u.%u:%u (%s%d)\n", + IPQUADPORT(req->r_request->hdr.dst.addr.ipaddr), + ENTITY_NAME(req->r_request->hdr.dst.name)); +} + +static ssize_t req_osd_op_show(struct ceph_osd_request *req, + struct ceph_osd_request_attr *attr, char *buf) +{ + struct ceph_osd_request_head *head = req->r_request->front.iov_base; + struct ceph_osd_op *op; + int num_ops; + int pos = 0; + int opcode; + int i; + + op = (void *)(head + 1); + + pos += sprintf(buf, "oid=%llx.%08x (snap=%lld)\n", + le64_to_cpu(head->oid.ino), + le32_to_cpu(head->oid.bno), + le64_to_cpu(head->oid.snap)); + + num_ops = le16_to_cpu(head->num_ops); + + for (i=0; iop); + + pos += sprintf(buf + pos, "%s\n", ceph_osd_op_name(opcode)); + op++; + } + + return pos; +} + +int ceph_sysfs_osd_req_init(struct ceph_osd_client *osdc, struct ceph_osd_request *req) +{ + int ret = 0; + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25) + ret = kobject_init_and_add(&req->kobj, &ceph_osd_request_ops, + &osdc->kobj, "%d", req->r_tid); + if (ret) + goto out; + + ADD_ENTITY_ATTR(req, k_osd, "osd", 0400, req_osd_show, NULL); + ADD_ENTITY_ATTR(req, k_op, "op", 0400, req_osd_op_show, NULL); + + return 0; +out: +#endif + return ret; +} + +void ceph_sysfs_osd_req_cleanup(struct ceph_osd_request *req) +{ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25) + kobject_del(&req->kobj); +#endif +} + /* * ceph attrs */ -- 2.39.5