Skip to contentSkip to conversation

rbd: make sure we have latest osdmap on 'rbd map'

PATCH Superseded Ilya Dryomov 2 participants 7 messages Apr 24, 2014 – May 7, 2014

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover rbd: make sure we have latest osdmap on 'rbd map'

Hello,

This is a rewrite of the fix for #8184 to use MMonGetVersion message instead of a kludgy timeout.

Thanks,

Ilya

Ilya Dryomov (3):
libceph: mon_get_version request infrastructure
libceph: add ceph_monc_wait_osdmap()
rbd: make sure we have latest osdmap on 'rbd map'

 drivers/block/rbd.c             |   27 ++++++--
 include/linux/ceph/mon_client.h |   13 ++--
 net/ceph/ceph_common.c          |    2 +
 net/ceph/debugfs.c              |    2 +
 net/ceph/mon_client.c           |  146 +++++++++++++++++++++++++++++++++++++--
 5 files changed, 175 insertions(+), 15 deletions(-)
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 1/3 libceph: mon_get_version request infrastructure

Add support for mon_get_version requests to libceph. This reuses much of the ceph_mon_generic_request infrastructure, with one exception. The mon_get_version reply hdr->tid is always 0 and that makes it impossible to lookup ceph_mon_generic_request contexts by tid in get_generic_reply(). So, instead of preallocating reply messages like its done for statfs and poolop requests, we allocate a reply message on the reply path. This can probably interfere with revoke, but I don't see a better way.

---
 include/linux/ceph/mon_client.h |   11 ++--
 net/ceph/ceph_common.c          |    2 +
 net/ceph/debugfs.c              |    2 +
 net/ceph/mon_client.c           |  119 ++++++++++++++++++++++++++++++++++++---
 4 files changed, 123 insertions(+), 11 deletions(-)
include/linux/ceph/mon_client.h +7 -4
index a486f390dfbe..d8060dd87f16 100644
@@ -40,9 +40,9 @@ struct ceph_mon_request {
 };
 
 /*
- * ceph_mon_generic_request is being used for the statfs and poolop requests
- * which are bening done a bit differently because we need to get data back
- * to the caller
+ * ceph_mon_generic_request is being used for the statfs, poolop and
+ * mon_get_version requests which are being done a bit differently
+ * because we need to get data back to the caller
  */
 struct ceph_mon_generic_request {
 	struct kref kref;
@@ -53,7 +53,7 @@ struct ceph_mon_generic_request {
 	int buf_len;
 	struct completion completion;
 	struct ceph_msg *request;  /* original request */
-	struct ceph_msg *reply;    /* and reply */
+	struct ceph_msg *reply;    /* and reply, NULL for mon_get_version */
 };
 
 struct ceph_mon_client {
@@ -108,6 +108,9 @@ extern void ceph_monc_request_next_osdmap(struct ceph_mon_client *monc);
 extern int ceph_monc_do_statfs(struct ceph_mon_client *monc,
 			       struct ceph_statfs *buf);
 
+extern int ceph_monc_do_get_version(struct ceph_mon_client *monc,
+				    const char *what, u64 *newest);
+
 extern int ceph_monc_open_session(struct ceph_mon_client *monc);
 
 extern int ceph_monc_validate_auth(struct ceph_mon_client *monc);
net/ceph/ceph_common.c +2 -0
index 67d7721d237e..1675021d8c12 100644
@@ -72,6 +72,8 @@ const char *ceph_msg_type_name(int type)
 	case CEPH_MSG_MON_SUBSCRIBE_ACK: return "mon_subscribe_ack";
 	case CEPH_MSG_STATFS: return "statfs";
 	case CEPH_MSG_STATFS_REPLY: return "statfs_reply";
+	case CEPH_MSG_MON_GET_VERSION: return "mon_get_version";
+	case CEPH_MSG_MON_GET_VERSION_REPLY: return "mon_get_version_reply";
 	case CEPH_MSG_MDS_MAP: return "mds_map";
 	case CEPH_MSG_CLIENT_SESSION: return "client_session";
 	case CEPH_MSG_CLIENT_RECONNECT: return "client_reconnect";
net/ceph/debugfs.c +2 -0
index 10421a4b76f8..45405aadee11 100644
@@ -127,6 +127,8 @@ static int monc_show(struct seq_file *s, void *p)
 		op = le16_to_cpu(req->request->hdr.type);
 		if (op == CEPH_MSG_STATFS)
 			seq_printf(s, "%lld statfs\n", req->tid);
+		else if (op == CEPH_MSG_MON_GET_VERSION)
+			seq_printf(s, "%llu get_version", req->tid);
 		else
 			seq_printf(s, "%lld unknown\n", req->tid);
 	}
net/ceph/mon_client.c +112 -7

165 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#2 lore raw

PATCH 2/3 libceph: add ceph_monc_wait_osdmap()

In reply to Ilya Dryomov

Add ceph_monc_wait_osdmap(), which will block until the osdmap with the specified epoch is received or timeout occurs.

Export both of these as they are going to be needed by rbd.

---
 include/linux/ceph/mon_client.h |    2 ++
 net/ceph/mon_client.c           |   27 +++++++++++++++++++++++++++
 2 files changed, 29 insertions(+)
include/linux/ceph/mon_client.h +2 -0
index d8060dd87f16..99ea0d60042f 100644
@@ -104,6 +104,8 @@ extern int ceph_monc_got_mdsmap(struct ceph_mon_client *monc, u32 have);
 extern int ceph_monc_got_osdmap(struct ceph_mon_client *monc, u32 have);
 
 extern void ceph_monc_request_next_osdmap(struct ceph_mon_client *monc);
+extern int ceph_monc_wait_osdmap(struct ceph_mon_client *monc, u32 epoch,
+				 unsigned long timeout);
 
 extern int ceph_monc_do_statfs(struct ceph_mon_client *monc,
 			       struct ceph_statfs *buf);
net/ceph/mon_client.c +27 -0
index d64023965d1c..7aa1ab1dbbf6 100644
@@ -296,6 +296,33 @@ void ceph_monc_request_next_osdmap(struct ceph_mon_client *monc)
 		__send_subscribe(monc);
 	mutex_unlock(&monc->mutex);
 }
+EXPORT_SYMBOL(ceph_monc_request_next_osdmap);
+
+int ceph_monc_wait_osdmap(struct ceph_mon_client *monc, u32 epoch,
+			  unsigned long timeout)
+{
+	unsigned long started = jiffies;
+	int ret;
+
+	mutex_lock(&monc->mutex);
+	while (monc->have_osdmap < epoch) {
+		mutex_unlock(&monc->mutex);
+
+		if (timeout != 0 && time_after_eq(jiffies, started + timeout))
+			return -ETIMEDOUT;
+
+		ret = wait_event_interruptible_timeout(monc->client->auth_wq,
+					 monc->have_osdmap >= epoch, timeout);
+		if (ret < 0)
+			return ret;
+
+		mutex_lock(&monc->mutex);
+	}
+
+	mutex_unlock(&monc->mutex);
+	return 0;
+}
+EXPORT_SYMBOL(ceph_monc_wait_osdmap);
 
 /*
  *
Signature · 1 line
1.7.10.4
#3 lore raw

PATCH 3/3 rbd: make sure we have latest osdmap on 'rbd map'

In reply to Ilya Dryomov

Given an existing idle mapping (img1), mapping an image (img2) in a newly created pool (pool2) fails:

    $ ceph osd pool create pool1 8 8
    $ rbd create --size 1000 pool1/img1
    $ sudo rbd map pool1/img1
    $ ceph osd pool create pool2 8 8
    $ rbd create --size 1000 pool2/img2
    $ sudo rbd map pool2/img2
    rbd: sysfs write failed
    rbd: map failed: (2) No such file or directory

This is because client instances are shared by default and we don't request an osdmap update when bumping a ref on an existing client. The fix is to use the mon_get_version request to see if the osdmap we have is the latest, and block until the requested update is received if it's not.

---
 drivers/block/rbd.c |   27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)
drivers/block/rbd.c +23 -4
index 552a2edcaa74..a3734726eef9 100644
@@ -723,15 +723,34 @@ static int parse_rbd_opts_token(char *c, void *private)
 static struct rbd_client *rbd_get_client(struct ceph_options *ceph_opts)
 {
 	struct rbd_client *rbdc;
+	u64 newest_epoch;
 
 	mutex_lock_nested(&client_mutex, SINGLE_DEPTH_NESTING);
 	rbdc = rbd_client_find(ceph_opts);
-	if (rbdc)	/* using an existing client */
-		ceph_destroy_options(ceph_opts);
-	else
+	if (!rbdc) {
 		rbdc = rbd_client_create(ceph_opts);
-	mutex_unlock(&client_mutex);
+		mutex_unlock(&client_mutex);
+		return rbdc;
+	}
+
+	/*
+	 * Using an existing client, make sure we've got the latest
+	 * osdmap.  Ignore the errors though, as failing to get it
+	 * doesn't necessarily prevent from working.
+	 */
+	if (ceph_monc_do_get_version(&rbdc->client->monc, "osdmap",
+				     &newest_epoch) < 0)
+		goto out;
+
+	if (rbdc->client->osdc.osdmap->epoch < newest_epoch) {
+		ceph_monc_request_next_osdmap(&rbdc->client->monc);
+		(void) ceph_monc_wait_osdmap(&rbdc->client->monc, newest_epoch,
+				    rbdc->client->options->mount_timeout * HZ);
+	}
 
+out:
+	mutex_unlock(&client_mutex);
+	ceph_destroy_options(ceph_opts);
 	return rbdc;
 }
 
Signature · 1 line
1.7.10.4
#4 lore raw

PATCH v2 1/1 rbd: make sure we have latest osdmap on 'rbd map'

Given an existing idle mapping (img1), mapping an image (img2) in a newly created pool (pool2) fails:

    $ ceph osd pool create pool1 8 8
    $ rbd create --size 1000 pool1/img1
    $ sudo rbd map pool1/img1
    $ ceph osd pool create pool2 8 8
    $ rbd create --size 1000 pool2/img2
    $ sudo rbd map pool2/img2
    rbd: sysfs write failed
    rbd: map failed: (2) No such file or directory

This is because client instances are shared by default and we don't request an osdmap update when bumping a ref on an existing client. The fix is to use the mon_get_version request to see if the osdmap we have is the latest, and block until the requested update is received if it's not.

---
v2:
- send mon_get_version request and wait for a reply only if we were unable to locate the pool (i.e. don't hurt the common case)

 drivers/block/rbd.c |   36 +++++++++++++++++++++++++++++++++---
 1 file changed, 33 insertions(+), 3 deletions(-)
drivers/block/rbd.c +33 -3
index 552a2edcaa74..daf7b4659b4a 100644
@@ -4683,6 +4683,38 @@ out_err:
 }
 
 /*
+ * Return pool id (>= 0) or a negative error code.
+ */
+static int rbd_add_get_pool_id(struct rbd_client *rbdc, const char *pool_name)
+{
+	u64 newest_epoch;
+	unsigned long timeout = rbdc->client->options->mount_timeout * HZ;
+	int tries = 0;
+	int ret;
+
+again:
+	ret = ceph_pg_poolid_by_name(rbdc->client->osdc.osdmap, pool_name);
+	if (ret == -ENOENT && tries++ < 1) {
+		ret = ceph_monc_do_get_version(&rbdc->client->monc, "osdmap",
+					       &newest_epoch);
+		if (ret < 0)
+			return ret;
+
+		if (rbdc->client->osdc.osdmap->epoch < newest_epoch) {
+			ceph_monc_request_next_osdmap(&rbdc->client->monc);
+			(void) ceph_monc_wait_osdmap(&rbdc->client->monc,
+						     newest_epoch, timeout);
+			goto again;
+		} else {
+			/* the osdmap we have is new enough */
+			return -ENOENT;
+		}
+	}
+
+	return ret;
+}
+
+/*
  * An rbd format 2 image has a unique identifier, distinct from the
  * name given to it by the user.  Internally, that identifier is
  * what's used to specify the names of objects related to the image.
@@ -5053,7 +5085,6 @@ static ssize_t do_rbd_add(struct bus_type *bus,
 	struct rbd_options *rbd_opts = NULL;
 	struct rbd_spec *spec = NULL;
 	struct rbd_client *rbdc;
-	struct ceph_osd_client *osdc;
 	bool read_only;
 	int rc = -ENOMEM;
 
@@ -5075,8 +5106,7 @@ static ssize_t do_rbd_add(struct bus_type *bus,
 	}
 
 	/* pick the pool */
-	osdc = &rbdc->client->osdc;
-	rc = ceph_pg_poolid_by_name(osdc->osdmap, spec->pool_name);
+	rc = rbd_add_get_pool_id(rbdc, spec->pool_name);
 	if (rc < 0)
 		goto err_out_client;
 	spec->pool_id = (u64)rc;
Signature · 1 line
1.7.10.4
#5 lore raw
In reply to Ilya Dryomov
Quoted 12 lines · Ilya Dryomov

Given an existing idle mapping (img1), mapping an image (img2) in a newly created pool (pool2) fails:

    $ ceph osd pool create pool1 8 8
    $ rbd create --size 1000 pool1/img1
    $ sudo rbd map pool1/img1
    $ ceph osd pool create pool2 8 8
    $ rbd create --size 1000 pool2/img2
    $ sudo rbd map pool2/img2
    rbd: sysfs write failed
    rbd: map failed: (2) No such file or directory
Quoted 5 lines

This is because client instances are shared by default and we don't request an osdmap update when bumping a ref on an existing client. The fix is to use the mon_get_version request to see if the osdmap we have is the latest, and block until the requested update is received if it's not.

This is slightly more heavyweight than the userspace client's approach. There, we only check for a newer osdmap if we find that the pool doesn't exist. That shouldn't be too difficult to mirror here... probably just expose a wait_for_latest_map() function, and call that + retry from the rbd map code?

sage

Quoted 60 lines
---
 drivers/block/rbd.c |   27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)
drivers/block/rbd.c +23 -4
index 552a2edcaa74..a3734726eef9 100644
@@ -723,15 +723,34 @@ static int parse_rbd_opts_token(char *c, void *private)
 static struct rbd_client *rbd_get_client(struct ceph_options *ceph_opts)
 {
 	struct rbd_client *rbdc;
+	u64 newest_epoch;
 
 	mutex_lock_nested(&client_mutex, SINGLE_DEPTH_NESTING);
 	rbdc = rbd_client_find(ceph_opts);
-	if (rbdc)	/* using an existing client */
-		ceph_destroy_options(ceph_opts);
-	else
+	if (!rbdc) {
 		rbdc = rbd_client_create(ceph_opts);
-	mutex_unlock(&client_mutex);
+		mutex_unlock(&client_mutex);
+		return rbdc;
+	}
+
+	/*
+	 * Using an existing client, make sure we've got the latest
+	 * osdmap.  Ignore the errors though, as failing to get it
+	 * doesn't necessarily prevent from working.
+	 */
+	if (ceph_monc_do_get_version(&rbdc->client->monc, "osdmap",
+				     &newest_epoch) < 0)
+		goto out;
+
+	if (rbdc->client->osdc.osdmap->epoch < newest_epoch) {
+		ceph_monc_request_next_osdmap(&rbdc->client->monc);
+		(void) ceph_monc_wait_osdmap(&rbdc->client->monc, newest_epoch,
+				    rbdc->client->options->mount_timeout * HZ);
+	}
 
+out:
+	mutex_unlock(&client_mutex);
+	ceph_destroy_options(ceph_opts);
 	return rbdc;
 }
 
Signature · 6 lines
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#6 lore raw
Quoted 19 lines · Sage Weil
Quoted 12 lines · Ilya Dryomov

Given an existing idle mapping (img1), mapping an image (img2) in a newly created pool (pool2) fails:

    $ ceph osd pool create pool1 8 8
    $ rbd create --size 1000 pool1/img1
    $ sudo rbd map pool1/img1
    $ ceph osd pool create pool2 8 8
    $ rbd create --size 1000 pool2/img2
    $ sudo rbd map pool2/img2
    rbd: sysfs write failed
    rbd: map failed: (2) No such file or directory
Quoted 5 lines

This is because client instances are shared by default and we don't request an osdmap update when bumping a ref on an existing client. The fix is to use the mon_get_version request to see if the osdmap we have is the latest, and block until the requested update is received if it's not.

Quoted 5 lines

This is slightly more heavyweight than the userspace client's approach. There, we only check for a newer osdmap if we find that the pool doesn't exist. That shouldn't be too difficult to mirror here... probably just expose a wait_for_latest_map() function, and call that + retry from the rbd map code?

(Der, and I see now that your 2/3 patch already exposes that method. :)

sage

Quoted 69 lines

sage

Quoted 60 lines
---
 drivers/block/rbd.c |   27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)
drivers/block/rbd.c +23 -4
index 552a2edcaa74..a3734726eef9 100644
@@ -723,15 +723,34 @@ static int parse_rbd_opts_token(char *c, void *private)
 static struct rbd_client *rbd_get_client(struct ceph_options *ceph_opts)
 {
 	struct rbd_client *rbdc;
+	u64 newest_epoch;
 
 	mutex_lock_nested(&client_mutex, SINGLE_DEPTH_NESTING);
 	rbdc = rbd_client_find(ceph_opts);
-	if (rbdc)	/* using an existing client */
-		ceph_destroy_options(ceph_opts);
-	else
+	if (!rbdc) {
 		rbdc = rbd_client_create(ceph_opts);
-	mutex_unlock(&client_mutex);
+		mutex_unlock(&client_mutex);
+		return rbdc;
+	}
+
+	/*
+	 * Using an existing client, make sure we've got the latest
+	 * osdmap.  Ignore the errors though, as failing to get it
+	 * doesn't necessarily prevent from working.
+	 */
+	if (ceph_monc_do_get_version(&rbdc->client->monc, "osdmap",
+				     &newest_epoch) < 0)
+		goto out;
+
+	if (rbdc->client->osdc.osdmap->epoch < newest_epoch) {
+		ceph_monc_request_next_osdmap(&rbdc->client->monc);
+		(void) ceph_monc_wait_osdmap(&rbdc->client->monc, newest_epoch,
+				    rbdc->client->options->mount_timeout * HZ);
+	}
 
+out:
+	mutex_unlock(&client_mutex);
+	ceph_destroy_options(ceph_opts);
 	return rbdc;
 }
 
Signature · 6 lines
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

--
To unsubscribe from this list: send the line "unsubscribe ceph-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html