]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
kclient: add mon enries for sysfs
authorYehuda Sadeh <yehuda@hq.newdream.net>
Tue, 10 Mar 2009 22:16:15 +0000 (15:16 -0700)
committerSage Weil <sage@newdream.net>
Tue, 10 Mar 2009 22:24:07 +0000 (15:24 -0700)
src/kernel/mon_client.c
src/kernel/mon_client.h
src/kernel/super.h
src/kernel/sysfs.c

index 085e8ecdc040d654176361ae4dbfcd1d8837af7f..a2431603635390571d4baf1eb156deb31aca2527 100644 (file)
@@ -84,7 +84,7 @@ static int pick_mon(struct ceph_mon_client *monc, int newmon)
 /*
  * Generic timeout mechanism for monitor requests
  */
-static void reschedule_timeout(struct ceph_mon_request_type *req)
+static void reschedule_timeout(struct ceph_mon_request *req)
 {
        schedule_delayed_work(&req->delayed_work, req->delay);
        if (req->delay < MAX_DELAY_INTERVAL)
@@ -95,8 +95,8 @@ static void reschedule_timeout(struct ceph_mon_request_type *req)
 
 static void retry_request(struct work_struct *work)
 {
-       struct ceph_mon_request_type *req =
-               container_of(work, struct ceph_mon_request_type,
+       struct ceph_mon_request *req =
+               container_of(work, struct ceph_mon_request,
                             delayed_work.work);
 
        /*
@@ -111,14 +111,14 @@ static void retry_request(struct work_struct *work)
                schedule_delayed_work(&req->delayed_work, BASE_DELAY_INTERVAL);
 }
 
-static void cancel_timeout(struct ceph_mon_request_type *req)
+static void cancel_timeout(struct ceph_mon_request *req)
 {
        cancel_delayed_work_sync(&req->delayed_work);
        req->delay = BASE_DELAY_INTERVAL;
 }
 
 static void init_request_type(struct ceph_mon_client *monc,
-                             struct ceph_mon_request_type *req,
+                             struct ceph_mon_request *req,
                              ceph_monc_request_func_t func)
 {
        req->monc = monc;
@@ -313,20 +313,23 @@ bad:
 /*
  * (re)send a statfs request
  */
-static int send_statfs(struct ceph_mon_client *monc, u64 tid, int newmon)
+static int send_statfs(struct ceph_mon_client *monc,
+                      struct ceph_mon_statfs_request *req,
+                      int newmon)
 {
        struct ceph_msg *msg;
        struct ceph_mon_statfs *h;
        int mon = pick_mon(monc, newmon ? 1:-1);
 
-       dout(10, "send_statfs to mon%d tid %llu\n", mon, tid);
+       dout(10, "send_statfs to mon%d tid %llu\n", mon, req->tid);
        msg = ceph_msg_new(CEPH_MSG_STATFS, sizeof(*h), 0, 0, NULL);
        if (IS_ERR(msg))
                return PTR_ERR(msg);
        h = msg->front.iov_base;
        h->fsid = monc->monmap->fsid;
-       h->tid = cpu_to_le64(tid);
+       h->tid = cpu_to_le64(req->tid);
        msg->hdr.dst = monc->monmap->mon_inst[mon];
+       ceph_sysfs_mon_statfs_req_init(monc, req, msg);
        ceph_msg_send(monc->client->msgr, msg, 0);
        return 0;
 }
@@ -347,6 +350,7 @@ int ceph_monc_do_statfs(struct ceph_mon_client *monc, struct ceph_statfs *buf)
        req.tid = ++monc->last_tid;
        req.last_attempt = jiffies;
        req.delay = BASE_DELAY_INTERVAL;
+       memset(&req.kobj, 0, sizeof(req.kobj));
        if (radix_tree_insert(&monc->statfs_request_tree, req.tid, &req) < 0) {
                mutex_unlock(&monc->statfs_mutex);
                derr(10, "ENOMEM in do_statfs\n");
@@ -359,11 +363,12 @@ int ceph_monc_do_statfs(struct ceph_mon_client *monc, struct ceph_statfs *buf)
        mutex_unlock(&monc->statfs_mutex);
 
        /* send request and wait */
-       err = send_statfs(monc, req.tid, 0);
+       err = send_statfs(monc, &req, 0);
        if (!err)
                err = wait_for_completion_interruptible(&req.completion);
 
        mutex_lock(&monc->statfs_mutex);
+       ceph_sysfs_mon_statfs_req_cleanup(&req);
        radix_tree_delete(&monc->statfs_request_tree, req.tid);
        monc->num_statfs_requests--;
        if (monc->num_statfs_requests == 0)
@@ -403,7 +408,7 @@ static void do_statfs_check(struct work_struct *work)
                        req->last_attempt = jiffies;
                        if (req->delay < MAX_DELAY_INTERVAL)
                                req->delay *= 2;
-                       send_statfs(monc, req->tid, newmon);
+                       send_statfs(monc, req, newmon);
                        newmon = 0;
                }
        }
index 5b05b243523526213bb3c52b17265885e0722912..fbe1665e8c14e0ec2ca7c2192d1c6452584ec8ee 100644 (file)
@@ -36,13 +36,32 @@ struct ceph_monmap {
 };
 
 struct ceph_mon_client;
+struct ceph_mon_statfs_request;
+
+struct ceph_mon_client_attr {
+       struct attribute attr;
+       ssize_t (*show)(struct ceph_mon_client *, struct ceph_mon_client_attr *,
+                       char *);
+       ssize_t (*store)(struct ceph_mon_client *, struct ceph_mon_client_attr *,
+                       const char *, size_t);
+};
+
+struct ceph_mon_statfs_request_attr {
+       struct attribute attr;
+       ssize_t (*show)(struct ceph_mon_statfs_request *, struct ceph_mon_statfs_request_attr *,
+                       char *);
+       ssize_t (*store)(struct ceph_mon_statfs_request *, struct ceph_mon_statfs_request_attr *,
+                       const char *, size_t);
+       struct ceph_entity_inst dst;
+};
 
 /*
  * Generic mechanism for resending monitor requests.
  */
 typedef void (*ceph_monc_request_func_t)(struct ceph_mon_client *monc,
                                         int newmon);
-struct ceph_mon_request_type {
+struct ceph_mon_request {
+        struct kobject kobj;
        struct ceph_mon_client *monc;
        struct delayed_work delayed_work;
        unsigned long delay;
@@ -52,6 +71,8 @@ struct ceph_mon_request_type {
 /* statfs() is done a bit differently */
 struct ceph_mon_statfs_request {
        u64 tid;
+        struct kobject kobj;
+        struct ceph_mon_statfs_request_attr k_op, k_mon;
        int result;
        struct ceph_statfs *buf;
        struct completion completion;
@@ -72,9 +93,12 @@ struct ceph_mon_client {
 
        /* mds/osd map or umount requests */
        struct mutex req_mutex;
-       struct ceph_mon_request_type mdsreq, osdreq, umountreq;
+       struct ceph_mon_request mdsreq, osdreq, umountreq;
        u32 want_mdsmap;
        u32 want_osdmap;
+
+       struct kobject kobj;
+        struct ceph_mon_client_attr k_want_osdmap, k_want_mdsmap;
 };
 
 extern struct ceph_monmap *ceph_monmap_decode(void *p, void *end);
index f6b0b8d109a7265d37e5a9d43c3fff2e6151e023..5c19c5a5800ad89c1dd29c54c1fa8a598f5b5fa5 100644 (file)
@@ -803,6 +803,10 @@ extern int ceph_sysfs_mds_req_init(struct ceph_mds_client *mdsc, struct ceph_mds
 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);
+extern int ceph_sysfs_mon_statfs_req_init(struct ceph_mon_client *monc, struct ceph_mon_statfs_request *req,
+                                         struct ceph_msg *msg);
+extern void ceph_sysfs_mon_statfs_req_cleanup(struct ceph_mon_statfs_request *req);
+
 
 static inline struct inode *get_dentry_parent_inode(struct dentry *dentry)
 {
index 38ce648bd8a2dea59c28297ba72f36091928aab6..119d1f701b6c659abde717540492883485978d38 100644 (file)
@@ -57,6 +57,7 @@ static struct kobj_type name##_ops = {                                        \
 DEF_ATTR_OP(ceph_client)
 DEF_ATTR_OP(ceph_mds_request)
 DEF_ATTR_OP(ceph_osd_request)
+DEF_ATTR_OP(ceph_mon_statfs_request)
 
 /*
  * per-client attributes
@@ -156,6 +157,18 @@ static ssize_t osdmap_show(struct ceph_client *client,
        return pos;
 }
 
+static ssize_t req_mon_want_osdmap_show(struct ceph_mon_client *monc,
+                          struct ceph_mon_client_attr *attr, char *buf)
+{
+       return sprintf(buf, "%u\n", monc->want_osdmap);
+}
+
+static ssize_t req_mon_want_mdsmap_show(struct ceph_mon_client *monc,
+                          struct ceph_mon_client_attr *attr, char *buf)
+{
+       return sprintf(buf, "%u\n", monc->want_mdsmap);
+}
+
 static struct kobj_type entity_ops = {
        .sysfs_ops = &ceph_client_sysfs_ops,
 };
@@ -181,10 +194,17 @@ int ceph_sysfs_client_init(struct ceph_client *client)
        if (ret)
                goto out;
 
+       ret = kobject_init_and_add(&client->monc.kobj, &entity_ops,
+                                  &client->kobj, "monc");
+       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);
        ADD_ENTITY_ATTR(client, k_osdmap, "osdmap", 0400, osdmap_show, NULL);
+       ADD_ENTITY_ATTR((&client->monc), k_want_osdmap, "want_osdmap", 0400, req_mon_want_osdmap_show, NULL);
+       ADD_ENTITY_ATTR((&client->monc), k_want_mdsmap, "want_mdsmap", 0400, req_mon_want_mdsmap_show, NULL);
        return 0;
 
 out:
@@ -334,6 +354,48 @@ void ceph_sysfs_osd_req_cleanup(struct ceph_osd_request *req)
 #endif
 }
 
+static ssize_t req_mon_show(struct ceph_mon_statfs_request *req,
+                          struct ceph_mon_statfs_request_attr *attr, char *buf)
+{
+       return sprintf(buf, "%u.%u.%u.%u:%u (%s%d)\n",
+                       IPQUADPORT(attr->dst.addr.ipaddr),
+                       ENTITY_NAME(attr->dst.name));
+}
+
+static ssize_t req_mon_op_show(struct ceph_mon_statfs_request *req,
+                          struct ceph_mon_statfs_request_attr *attr, char *buf)
+{
+       return sprintf(buf, "statfs\n");
+}
+
+int ceph_sysfs_mon_statfs_req_init(struct ceph_mon_client *monc, struct ceph_mon_statfs_request *req,
+                                  struct ceph_msg *msg)
+{
+       int ret = 0;
+
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)
+       ret = kobject_init_and_add(&req->kobj, &ceph_mon_statfs_request_ops,
+                                  &monc->kobj, "%d", req->tid);
+       if (ret)
+               goto out;
+
+       req->k_mon.dst = msg->hdr.dst;
+       ADD_ENTITY_ATTR(req, k_mon, "mon", 0400, req_mon_show, NULL);
+       ADD_ENTITY_ATTR(req, k_op, "op", 0400, req_mon_op_show, NULL);
+
+       return 0;
+out:
+#endif
+       return ret;
+}
+
+void ceph_sysfs_mon_statfs_req_cleanup(struct ceph_mon_statfs_request *req)
+{
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 25)
+       kobject_del(&req->kobj);
+#endif
+}
+
 /*
  * ceph attrs
  */