All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v8 0/7] ceph: implement -ENOSPC handling in cephfs
@ 2017-04-17 16:42 Jeff Layton
  2017-04-17 16:42 ` [PATCH v8 1/7] libceph: remove req->r_replay_version Jeff Layton
                   ` (6 more replies)
  0 siblings, 7 replies; 13+ messages in thread
From: Jeff Layton @ 2017-04-17 16:42 UTC (permalink / raw)
  To: idryomov, zyan, sage; +Cc: jspray, ceph-devel

v8: fix deadlock when releasing caps after a cancelled operation
    set epoch_barrier before cancelling operations on full conditions

v7: don't request a continuous sub when the epoch is not yet at the
    barrier. Don't set epoch barrier unless we aborted a call that
    may have already been sent. Use READ_ONCE in lockless ERROR_WRITE
    flag handling.

v6: reset barrier to current epoch when receiving map with full pool or
    at quota condition. Show epoch barrier in debugfs. Don't take osd->lock
    unnecessarily. Remove req->r_replay_version. Other cleanups and
    fixes suggested by Ilya.

v5: rebase onto ACK vs. commit changes

v4: eliminate map_cb and just call ceph_osdc_abort_on_full directly
Revert earlier patch flagging individual pages with error on writeback
failure. Add mechanism to force synchronous writes when writes start
failing, and reallowing async writes when they succeed.

v3: track "abort_on_full" behavior with a new bool in osd request
instead of a protocol flag. Remove some extraneous arguments from
various functions. Don't export have_pool_full, call it from the
abort_on_full callback instead.

v2: teach libcephfs how to hold on to requests until the right map
epoch appears, instead of delaying cap handling in the cephfs layer.

This patchset is an updated version of the patch series originally
done by John Spray and posted here:

    http://www.spinics.net/lists/ceph-devel/msg21257.html

This is ai small update to the set I posted a couple of weeks ago.

We hit a deadlock in testing that was due to taking the osdc->lock
recursively. While diagnosing that, I realized that we can end up
releasing caps as a result of a cancelled operation.

In that case, we probably want to ensure that the cap release message
has an updated epoch barrier in it, so there's also a change to
ceph_osdc_abort_on_full to set the epoch barrier prior to cancelling the
operations.

So far this seems to do well with the re-enabled ENOSPC testing in
teuthology, though we do have to make a small change to the testsuite to
compensate for a difference between kcephfs and ceph-fuse.  ceph-fuse
returns errors on a close if there were writeback issues prior to
closing. The kernel does not do that currently.

For now, we're leaving the kcephfs behavior as-is. I think this is a
place where we need to have consistent behavior across Linux
filesystems, and that means a larger discussion about what userspace
consumers really want here.

Jeff Layton (7):
  libceph: remove req->r_replay_version
  libceph: allow requests to return immediately on full conditions if
    caller wishes
  libceph: abort already submitted but abortable requests when map or
    pool goes full
  libceph: add an epoch_barrier field to struct ceph_osd_client
  ceph: handle epoch barriers in cap messages
  Revert "ceph: SetPageError() for writeback pages if writepages fails"
  ceph: when seeing write errors on an inode, switch to sync writes

 fs/ceph/addr.c                  |  10 ++--
 fs/ceph/caps.c                  |  21 +++++--
 fs/ceph/file.c                  |  32 ++++++-----
 fs/ceph/mds_client.c            |  20 +++++++
 fs/ceph/mds_client.h            |   7 ++-
 fs/ceph/super.h                 |  26 +++++++++
 include/linux/ceph/osd_client.h |   4 +-
 net/ceph/debugfs.c              |   7 +--
 net/ceph/osd_client.c           | 118 +++++++++++++++++++++++++++++++++++++---
 9 files changed, 208 insertions(+), 37 deletions(-)

-- 
2.9.3


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v8 1/7] libceph: remove req->r_replay_version
  2017-04-17 16:42 [PATCH v8 0/7] ceph: implement -ENOSPC handling in cephfs Jeff Layton
@ 2017-04-17 16:42 ` Jeff Layton
  2017-04-17 16:42 ` [PATCH v8 2/7] libceph: allow requests to return immediately on full conditions if caller wishes Jeff Layton
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 13+ messages in thread
From: Jeff Layton @ 2017-04-17 16:42 UTC (permalink / raw)
  To: idryomov, zyan, sage; +Cc: jspray, ceph-devel

Nothing uses this anymore with the removal of the ack vs. commit code.
Remove the field and just encode zeroes into place in the request
encoding.

Signed-off-by: Jeff Layton <jlayton@redhat.com>
Reviewed-by: Ilya Dryomov <idryomov@gmail.com>
---
 include/linux/ceph/osd_client.h | 1 -
 net/ceph/debugfs.c              | 4 +---
 net/ceph/osd_client.c           | 7 ++++---
 3 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/include/linux/ceph/osd_client.h b/include/linux/ceph/osd_client.h
index d6a625e75040..3fc9e7754a9b 100644
--- a/include/linux/ceph/osd_client.h
+++ b/include/linux/ceph/osd_client.h
@@ -192,7 +192,6 @@ struct ceph_osd_request {
 	unsigned long r_stamp;                /* jiffies, send or check time */
 	unsigned long r_start_stamp;          /* jiffies */
 	int r_attempts;
-	struct ceph_eversion r_replay_version; /* aka reassert_version */
 	u32 r_last_force_resend;
 	u32 r_map_dne_bound;
 
diff --git a/net/ceph/debugfs.c b/net/ceph/debugfs.c
index c62b2b029a6e..d7e63a4f5578 100644
--- a/net/ceph/debugfs.c
+++ b/net/ceph/debugfs.c
@@ -177,9 +177,7 @@ static void dump_request(struct seq_file *s, struct ceph_osd_request *req)
 	seq_printf(s, "%llu\t", req->r_tid);
 	dump_target(s, &req->r_t);
 
-	seq_printf(s, "\t%d\t%u'%llu", req->r_attempts,
-		   le32_to_cpu(req->r_replay_version.epoch),
-		   le64_to_cpu(req->r_replay_version.version));
+	seq_printf(s, "\t%d", req->r_attempts);
 
 	for (i = 0; i < req->r_num_ops; i++) {
 		struct ceph_osd_req_op *op = &req->r_ops[i];
diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
index b4500a8ab8b3..feb666c22381 100644
--- a/net/ceph/osd_client.c
+++ b/net/ceph/osd_client.c
@@ -1503,9 +1503,10 @@ static void encode_request(struct ceph_osd_request *req, struct ceph_msg *msg)
 	ceph_encode_32(&p, req->r_flags);
 	ceph_encode_timespec(p, &req->r_mtime);
 	p += sizeof(struct ceph_timespec);
-	/* aka reassert_version */
-	memcpy(p, &req->r_replay_version, sizeof(req->r_replay_version));
-	p += sizeof(req->r_replay_version);
+
+	/* reassert_version */
+	memset(p, 0, sizeof(struct ceph_eversion));
+	p += sizeof(struct ceph_eversion);
 
 	/* oloc */
 	ceph_start_encoding(&p, 5, 4,
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v8 2/7] libceph: allow requests to return immediately on full conditions if caller wishes
  2017-04-17 16:42 [PATCH v8 0/7] ceph: implement -ENOSPC handling in cephfs Jeff Layton
  2017-04-17 16:42 ` [PATCH v8 1/7] libceph: remove req->r_replay_version Jeff Layton
@ 2017-04-17 16:42 ` Jeff Layton
  2017-04-17 16:42 ` [PATCH v8 3/7] libceph: abort already submitted but abortable requests when map or pool goes full Jeff Layton
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 13+ messages in thread
From: Jeff Layton @ 2017-04-17 16:42 UTC (permalink / raw)
  To: idryomov, zyan, sage; +Cc: jspray, ceph-devel

Usually, when the osd map is flagged as full or the pool is at quota,
write requests just hang. This is not what we want for cephfs, where
it would be better to simply report -ENOSPC back to userland instead
of stalling.

If the caller knows that it will want an immediate error return instead
of blocking on a full or at-quota error condition then allow it to set a
flag to request that behavior.

Set that flag in ceph_osdc_new_request (since ceph.ko is the only caller),
and on any other write request from ceph.ko.

A later patch will deal with requests that were submitted before the new
map showing the full condition came in.

Reviewed-by: "Yan, Zheng” <zyan@redhat.com>
Reviewed-by: Ilya Dryomov <idryomov@gmail.com>
Signed-off-by: Jeff Layton <jlayton@redhat.com>
---
 fs/ceph/addr.c                  | 1 +
 fs/ceph/file.c                  | 1 +
 include/linux/ceph/osd_client.h | 1 +
 net/ceph/osd_client.c           | 7 +++++++
 4 files changed, 10 insertions(+)

diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c
index 1a3e1b40799a..7e3fae334620 100644
--- a/fs/ceph/addr.c
+++ b/fs/ceph/addr.c
@@ -1892,6 +1892,7 @@ static int __ceph_pool_perm_get(struct ceph_inode_info *ci,
 	err = ceph_osdc_start_request(&fsc->client->osdc, rd_req, false);
 
 	wr_req->r_mtime = ci->vfs_inode.i_mtime;
+	wr_req->r_abort_on_full = true;
 	err2 = ceph_osdc_start_request(&fsc->client->osdc, wr_req, false);
 
 	if (!err)
diff --git a/fs/ceph/file.c b/fs/ceph/file.c
index 356b7c76a2f1..cff35a1ff53c 100644
--- a/fs/ceph/file.c
+++ b/fs/ceph/file.c
@@ -712,6 +712,7 @@ static void ceph_aio_retry_work(struct work_struct *work)
 	req->r_callback = ceph_aio_complete_req;
 	req->r_inode = inode;
 	req->r_priv = aio_req;
+	req->r_abort_on_full = true;
 
 	ret = ceph_osdc_start_request(req->r_osdc, req, false);
 out:
diff --git a/include/linux/ceph/osd_client.h b/include/linux/ceph/osd_client.h
index 3fc9e7754a9b..8cf644197b1a 100644
--- a/include/linux/ceph/osd_client.h
+++ b/include/linux/ceph/osd_client.h
@@ -187,6 +187,7 @@ struct ceph_osd_request {
 	struct timespec r_mtime;              /* ditto */
 	u64 r_data_offset;                    /* ditto */
 	bool r_linger;                        /* don't resend on failure */
+	bool r_abort_on_full;		      /* return ENOSPC when full */
 
 	/* internal */
 	unsigned long r_stamp;                /* jiffies, send or check time */
diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
index feb666c22381..52a2019a2b64 100644
--- a/net/ceph/osd_client.c
+++ b/net/ceph/osd_client.c
@@ -961,6 +961,7 @@ struct ceph_osd_request *ceph_osdc_new_request(struct ceph_osd_client *osdc,
 				       truncate_size, truncate_seq);
 	}
 
+	req->r_abort_on_full = true;
 	req->r_flags = flags;
 	req->r_base_oloc.pool = layout->pool_id;
 	req->r_base_oloc.pool_ns = ceph_try_get_string(layout->pool_ns);
@@ -1627,6 +1628,7 @@ static void maybe_request_map(struct ceph_osd_client *osdc)
 		ceph_monc_renew_subs(&osdc->client->monc);
 }
 
+static void complete_request(struct ceph_osd_request *req, int err);
 static void send_map_check(struct ceph_osd_request *req);
 
 static void __submit_request(struct ceph_osd_request *req, bool wrlocked)
@@ -1636,6 +1638,7 @@ static void __submit_request(struct ceph_osd_request *req, bool wrlocked)
 	enum calc_target_result ct_res;
 	bool need_send = false;
 	bool promoted = false;
+	bool need_abort = false;
 
 	WARN_ON(req->r_tid);
 	dout("%s req %p wrlocked %d\n", __func__, req, wrlocked);
@@ -1670,6 +1673,8 @@ static void __submit_request(struct ceph_osd_request *req, bool wrlocked)
 		pr_warn_ratelimited("FULL or reached pool quota\n");
 		req->r_t.paused = true;
 		maybe_request_map(osdc);
+		if (req->r_abort_on_full)
+			need_abort = true;
 	} else if (!osd_homeless(osd)) {
 		need_send = true;
 	} else {
@@ -1686,6 +1691,8 @@ static void __submit_request(struct ceph_osd_request *req, bool wrlocked)
 	link_request(osd, req);
 	if (need_send)
 		send_request(req);
+	else if (need_abort)
+		complete_request(req, -ENOSPC);
 	mutex_unlock(&osd->lock);
 
 	if (ct_res == CALC_TARGET_POOL_DNE)
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v8 3/7] libceph: abort already submitted but abortable requests when map or pool goes full
  2017-04-17 16:42 [PATCH v8 0/7] ceph: implement -ENOSPC handling in cephfs Jeff Layton
  2017-04-17 16:42 ` [PATCH v8 1/7] libceph: remove req->r_replay_version Jeff Layton
  2017-04-17 16:42 ` [PATCH v8 2/7] libceph: allow requests to return immediately on full conditions if caller wishes Jeff Layton
@ 2017-04-17 16:42 ` Jeff Layton
  2017-04-17 16:42 ` [PATCH v8 4/7] libceph: add an epoch_barrier field to struct ceph_osd_client Jeff Layton
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 13+ messages in thread
From: Jeff Layton @ 2017-04-17 16:42 UTC (permalink / raw)
  To: idryomov, zyan, sage; +Cc: jspray, ceph-devel

When a Ceph volume hits capacity, a flag is set in the OSD map to
indicate that, and a new map is sprayed around the cluster. With cephfs
we want it to shut down any abortable requests that are in progress with
an -ENOSPC error as they'd just hang otherwise.

Add a new ceph_osdc_abort_on_full helper function to handle this. It
will first check whether there is an out-of-space condition in the
cluster and then walk the tree and abort any request that has
r_abort_on_full set with a -ENOSPC error. Call this new function
directly whenever we get a new OSD map.

Reviewed-by: "Yan, Zheng” <zyan@redhat.com>
Signed-off-by: Jeff Layton <jlayton@redhat.com>
---
 net/ceph/osd_client.c | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
index 52a2019a2b64..55b7585ccefd 100644
--- a/net/ceph/osd_client.c
+++ b/net/ceph/osd_client.c
@@ -1807,6 +1807,39 @@ static void abort_request(struct ceph_osd_request *req, int err)
 	complete_request(req, err);
 }
 
+/*
+ * Drop all pending requests that are stalled waiting on a full condition to
+ * clear, and complete them with ENOSPC as the return code.
+ */
+static void ceph_osdc_abort_on_full(struct ceph_osd_client *osdc)
+{
+	struct rb_node *n;
+
+	dout("enter abort_on_full\n");
+
+	if (!ceph_osdmap_flag(osdc, CEPH_OSDMAP_FULL) && !have_pool_full(osdc))
+		goto out;
+
+	for (n = rb_first(&osdc->osds); n; n = rb_next(n)) {
+		struct ceph_osd *osd = rb_entry(n, struct ceph_osd, o_node);
+		struct rb_node *m;
+
+		m = rb_first(&osd->o_requests);
+		while (m) {
+			struct ceph_osd_request *req = rb_entry(m,
+					struct ceph_osd_request, r_node);
+			m = rb_next(m);
+
+			if (req->r_abort_on_full &&
+			    (ceph_osdmap_flag(osdc, CEPH_OSDMAP_FULL) ||
+			     pool_full(osdc, req->r_t.target_oloc.pool)))
+				abort_request(req, -ENOSPC);
+		}
+	}
+out:
+	dout("return abort_on_full\n");
+}
+
 static void check_pool_dne(struct ceph_osd_request *req)
 {
 	struct ceph_osd_client *osdc = req->r_osdc;
@@ -3265,6 +3298,7 @@ void ceph_osdc_handle_map(struct ceph_osd_client *osdc, struct ceph_msg *msg)
 
 	kick_requests(osdc, &need_resend, &need_resend_linger);
 
+	ceph_osdc_abort_on_full(osdc);
 	ceph_monc_got_map(&osdc->client->monc, CEPH_SUB_OSDMAP,
 			  osdc->osdmap->epoch);
 	up_write(&osdc->lock);
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v8 4/7] libceph: add an epoch_barrier field to struct ceph_osd_client
  2017-04-17 16:42 [PATCH v8 0/7] ceph: implement -ENOSPC handling in cephfs Jeff Layton
                   ` (2 preceding siblings ...)
  2017-04-17 16:42 ` [PATCH v8 3/7] libceph: abort already submitted but abortable requests when map or pool goes full Jeff Layton
@ 2017-04-17 16:42 ` Jeff Layton
  2017-04-18 12:19   ` Jeff Layton
  2017-04-17 16:42 ` [PATCH v8 5/7] ceph: handle epoch barriers in cap messages Jeff Layton
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 13+ messages in thread
From: Jeff Layton @ 2017-04-17 16:42 UTC (permalink / raw)
  To: idryomov, zyan, sage; +Cc: jspray, ceph-devel

Cephfs can get cap update requests that contain a new epoch barrier in
them. When that happens we want to pause all OSD traffic until the right
map epoch arrives.

Add an epoch_barrier field to ceph_osd_client that is protected by the
osdc->lock rwsem. When the barrier is set, and the current OSD map
epoch is below that, pause the request target when submitting the
request or when revisiting it. Add a way for upper layers (cephfs)
to update the epoch_barrier as well.

If we get a new map, compare the new epoch against the barrier before
kicking requests and request another map if the map epoch is still lower
than the one we want.

If we get a map with a full pool, or at quota condition, then set the
barrier to the current epoch value.

Reviewed-by: "Yan, Zheng” <zyan@redhat.com>
Signed-off-by: Jeff Layton <jlayton@redhat.com>
Reviewed-by: Ilya Dryomov <idryomov@gmail.com>
---
 include/linux/ceph/osd_client.h |  2 ++
 net/ceph/debugfs.c              |  3 +-
 net/ceph/osd_client.c           | 76 ++++++++++++++++++++++++++++++++++++-----
 3 files changed, 72 insertions(+), 9 deletions(-)

diff --git a/include/linux/ceph/osd_client.h b/include/linux/ceph/osd_client.h
index 8cf644197b1a..85650b415e73 100644
--- a/include/linux/ceph/osd_client.h
+++ b/include/linux/ceph/osd_client.h
@@ -267,6 +267,7 @@ struct ceph_osd_client {
 	struct rb_root         osds;          /* osds */
 	struct list_head       osd_lru;       /* idle osds */
 	spinlock_t             osd_lru_lock;
+	u32		       epoch_barrier;
 	struct ceph_osd        homeless_osd;
 	atomic64_t             last_tid;      /* tid of last request */
 	u64                    last_linger_id;
@@ -305,6 +306,7 @@ extern void ceph_osdc_handle_reply(struct ceph_osd_client *osdc,
 				   struct ceph_msg *msg);
 extern void ceph_osdc_handle_map(struct ceph_osd_client *osdc,
 				 struct ceph_msg *msg);
+void ceph_osdc_update_epoch_barrier(struct ceph_osd_client *osdc, u32 eb);
 
 extern void osd_req_op_init(struct ceph_osd_request *osd_req,
 			    unsigned int which, u16 opcode, u32 flags);
diff --git a/net/ceph/debugfs.c b/net/ceph/debugfs.c
index d7e63a4f5578..71ba13927b3d 100644
--- a/net/ceph/debugfs.c
+++ b/net/ceph/debugfs.c
@@ -62,7 +62,8 @@ static int osdmap_show(struct seq_file *s, void *p)
 		return 0;
 
 	down_read(&osdc->lock);
-	seq_printf(s, "epoch %d flags 0x%x\n", map->epoch, map->flags);
+	seq_printf(s, "epoch %u barrier %u flags 0x%x\n", map->epoch,
+			osdc->epoch_barrier, map->flags);
 
 	for (n = rb_first(&map->pg_pools); n; n = rb_next(n)) {
 		struct ceph_pg_pool_info *pi =
diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
index 55b7585ccefd..beeac4f39aa5 100644
--- a/net/ceph/osd_client.c
+++ b/net/ceph/osd_client.c
@@ -1298,8 +1298,9 @@ static bool target_should_be_paused(struct ceph_osd_client *osdc,
 		       __pool_full(pi);
 
 	WARN_ON(pi->id != t->base_oloc.pool);
-	return (t->flags & CEPH_OSD_FLAG_READ && pauserd) ||
-	       (t->flags & CEPH_OSD_FLAG_WRITE && pausewr);
+	return ((t->flags & CEPH_OSD_FLAG_READ) && pauserd) ||
+	       ((t->flags & CEPH_OSD_FLAG_WRITE) && pausewr) ||
+	       (osdc->osdmap->epoch < osdc->epoch_barrier);
 }
 
 enum calc_target_result {
@@ -1654,8 +1655,13 @@ static void __submit_request(struct ceph_osd_request *req, bool wrlocked)
 		goto promote;
 	}
 
-	if ((req->r_flags & CEPH_OSD_FLAG_WRITE) &&
-	    ceph_osdmap_flag(osdc, CEPH_OSDMAP_PAUSEWR)) {
+	if (osdc->osdmap->epoch < osdc->epoch_barrier) {
+		dout("req %p epoch %u barrier %u\n", req, osdc->osdmap->epoch,
+		     osdc->epoch_barrier);
+		req->r_t.paused = true;
+		maybe_request_map(osdc);
+	} else if ((req->r_flags & CEPH_OSD_FLAG_WRITE) &&
+		   ceph_osdmap_flag(osdc, CEPH_OSDMAP_PAUSEWR)) {
 		dout("req %p pausewr\n", req);
 		req->r_t.paused = true;
 		maybe_request_map(osdc);
@@ -1809,17 +1815,48 @@ static void abort_request(struct ceph_osd_request *req, int err)
 
 /*
  * Drop all pending requests that are stalled waiting on a full condition to
- * clear, and complete them with ENOSPC as the return code.
+ * clear, and complete them with ENOSPC as the return code. Set the
+ * osdc->epoch_barrier to the latest map epoch that we've seen if any were
+ * cancelled.
  */
 static void ceph_osdc_abort_on_full(struct ceph_osd_client *osdc)
 {
 	struct rb_node *n;
+	bool victims = false;
 
 	dout("enter abort_on_full\n");
 
 	if (!ceph_osdmap_flag(osdc, CEPH_OSDMAP_FULL) && !have_pool_full(osdc))
 		goto out;
 
+	/* Scan list and see if there is anything to abort */
+	for (n = rb_first(&osdc->osds); n; n = rb_next(n)) {
+		struct ceph_osd *osd = rb_entry(n, struct ceph_osd, o_node);
+		struct rb_node *m;
+
+		m = rb_first(&osd->o_requests);
+		while (m) {
+			struct ceph_osd_request *req = rb_entry(m,
+					struct ceph_osd_request, r_node);
+			m = rb_next(m);
+
+			if (req->r_abort_on_full) {
+				victims = true;
+				break;
+			}
+		}
+		if (victims)
+			break;
+	}
+
+	if (!victims)
+		goto out;
+
+	/*
+	 * Update the barrier to current epoch since we know we have some
+	 * calls to be aborted in the tree.
+	 */
+	osdc->epoch_barrier = osdc->osdmap->epoch;
 	for (n = rb_first(&osdc->osds); n; n = rb_next(n)) {
 		struct ceph_osd *osd = rb_entry(n, struct ceph_osd, o_node);
 		struct rb_node *m;
@@ -1832,12 +1869,13 @@ static void ceph_osdc_abort_on_full(struct ceph_osd_client *osdc)
 
 			if (req->r_abort_on_full &&
 			    (ceph_osdmap_flag(osdc, CEPH_OSDMAP_FULL) ||
-			     pool_full(osdc, req->r_t.target_oloc.pool)))
+			     pool_full(osdc, req->r_t.target_oloc.pool))) {
 				abort_request(req, -ENOSPC);
+			}
 		}
 	}
 out:
-	dout("return abort_on_full\n");
+	dout("return abort_on_full barrier=%u\n", osdc->epoch_barrier);
 }
 
 static void check_pool_dne(struct ceph_osd_request *req)
@@ -3293,7 +3331,8 @@ void ceph_osdc_handle_map(struct ceph_osd_client *osdc, struct ceph_msg *msg)
 	pausewr = ceph_osdmap_flag(osdc, CEPH_OSDMAP_PAUSEWR) ||
 		  ceph_osdmap_flag(osdc, CEPH_OSDMAP_FULL) ||
 		  have_pool_full(osdc);
-	if (was_pauserd || was_pausewr || pauserd || pausewr)
+	if (was_pauserd || was_pausewr || pauserd || pausewr ||
+	    osdc->osdmap->epoch < osdc->epoch_barrier)
 		maybe_request_map(osdc);
 
 	kick_requests(osdc, &need_resend, &need_resend_linger);
@@ -3311,6 +3350,27 @@ void ceph_osdc_handle_map(struct ceph_osd_client *osdc, struct ceph_msg *msg)
 	up_write(&osdc->lock);
 }
 
+void ceph_osdc_update_epoch_barrier(struct ceph_osd_client *osdc, u32 eb)
+{
+	down_read(&osdc->lock);
+	if (unlikely(eb > osdc->epoch_barrier)) {
+		up_read(&osdc->lock);
+		down_write(&osdc->lock);
+		if (likely(eb > osdc->epoch_barrier)) {
+			dout("updating epoch_barrier from %u to %u\n",
+					osdc->epoch_barrier, eb);
+			osdc->epoch_barrier = eb;
+			/* Request map if we're not to the barrier yet */
+			if (eb > osdc->osdmap->epoch)
+				maybe_request_map(osdc);
+		}
+		up_write(&osdc->lock);
+	} else {
+		up_read(&osdc->lock);
+	}
+}
+EXPORT_SYMBOL(ceph_osdc_update_epoch_barrier);
+
 /*
  * Resubmit requests pending on the given osd.
  */
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v8 5/7] ceph: handle epoch barriers in cap messages
  2017-04-17 16:42 [PATCH v8 0/7] ceph: implement -ENOSPC handling in cephfs Jeff Layton
                   ` (3 preceding siblings ...)
  2017-04-17 16:42 ` [PATCH v8 4/7] libceph: add an epoch_barrier field to struct ceph_osd_client Jeff Layton
@ 2017-04-17 16:42 ` Jeff Layton
  2017-04-17 16:42 ` [PATCH v8 6/7] Revert "ceph: SetPageError() for writeback pages if writepages fails" Jeff Layton
  2017-04-17 16:42 ` [PATCH v8 7/7] ceph: when seeing write errors on an inode, switch to sync writes Jeff Layton
  6 siblings, 0 replies; 13+ messages in thread
From: Jeff Layton @ 2017-04-17 16:42 UTC (permalink / raw)
  To: idryomov, zyan, sage; +Cc: jspray, ceph-devel

Have the client store and update the osdc epoch_barrier when a cap
message comes in with one.

When sending cap messages, send the epoch barrier as well. This allows
clients to inform servers that their released caps may not be used until
a particular OSD map epoch.

Reviewed-by: "Yan, Zheng” <zyan@redhat.com>
Signed-off-by: Jeff Layton <jlayton@redhat.com>
---
 fs/ceph/caps.c       | 21 ++++++++++++++++-----
 fs/ceph/mds_client.c | 20 ++++++++++++++++++++
 fs/ceph/mds_client.h |  7 +++++--
 3 files changed, 41 insertions(+), 7 deletions(-)

diff --git a/fs/ceph/caps.c b/fs/ceph/caps.c
index 60185434162a..a3ebb632294e 100644
--- a/fs/ceph/caps.c
+++ b/fs/ceph/caps.c
@@ -1015,6 +1015,7 @@ static int send_cap_msg(struct cap_msg_args *arg)
 	void *p;
 	size_t extra_len;
 	struct timespec zerotime = {0};
+	struct ceph_osd_client *osdc = &arg->session->s_mdsc->fsc->client->osdc;
 
 	dout("send_cap_msg %s %llx %llx caps %s wanted %s dirty %s"
 	     " seq %u/%u tid %llu/%llu mseq %u follows %lld size %llu/%llu"
@@ -1076,8 +1077,12 @@ static int send_cap_msg(struct cap_msg_args *arg)
 	ceph_encode_64(&p, arg->inline_data ? 0 : CEPH_INLINE_NONE);
 	/* inline data size */
 	ceph_encode_32(&p, 0);
-	/* osd_epoch_barrier (version 5) */
-	ceph_encode_32(&p, 0);
+	/*
+	 * osd_epoch_barrier (version 5)
+	 * The epoch_barrier is protected osdc->lock, so READ_ONCE here in
+	 * case it was recently changed
+	 */
+	ceph_encode_32(&p, READ_ONCE(osdc->epoch_barrier));
 	/* oldest_flush_tid (version 6) */
 	ceph_encode_64(&p, arg->oldest_flush_tid);
 
@@ -3633,13 +3638,19 @@ void ceph_handle_caps(struct ceph_mds_session *session,
 		p += inline_len;
 	}
 
+	if (le16_to_cpu(msg->hdr.version) >= 5) {
+		struct ceph_osd_client	*osdc = &mdsc->fsc->client->osdc;
+		u32			epoch_barrier;
+
+		ceph_decode_32_safe(&p, end, epoch_barrier, bad);
+		ceph_osdc_update_epoch_barrier(osdc, epoch_barrier);
+	}
+
 	if (le16_to_cpu(msg->hdr.version) >= 8) {
 		u64 flush_tid;
 		u32 caller_uid, caller_gid;
-		u32 osd_epoch_barrier;
 		u32 pool_ns_len;
-		/* version >= 5 */
-		ceph_decode_32_safe(&p, end, osd_epoch_barrier, bad);
+
 		/* version >= 6 */
 		ceph_decode_64_safe(&p, end, flush_tid, bad);
 		/* version >= 7 */
diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
index 8cc4d4e8b077..f7bfc22eb39c 100644
--- a/fs/ceph/mds_client.c
+++ b/fs/ceph/mds_client.c
@@ -1552,9 +1552,15 @@ void ceph_send_cap_releases(struct ceph_mds_client *mdsc,
 	struct ceph_msg *msg = NULL;
 	struct ceph_mds_cap_release *head;
 	struct ceph_mds_cap_item *item;
+	struct ceph_osd_client *osdc = &mdsc->fsc->client->osdc;
 	struct ceph_cap *cap;
 	LIST_HEAD(tmp_list);
 	int num_cap_releases;
+	__le32	barrier, *cap_barrier;
+
+	down_read(&osdc->lock);
+	barrier = cpu_to_le32(osdc->epoch_barrier);
+	up_read(&osdc->lock);
 
 	spin_lock(&session->s_cap_lock);
 again:
@@ -1572,7 +1578,11 @@ void ceph_send_cap_releases(struct ceph_mds_client *mdsc,
 			head = msg->front.iov_base;
 			head->num = cpu_to_le32(0);
 			msg->front.iov_len = sizeof(*head);
+
+			msg->hdr.version = cpu_to_le16(2);
+			msg->hdr.compat_version = cpu_to_le16(1);
 		}
+
 		cap = list_first_entry(&tmp_list, struct ceph_cap,
 					session_caps);
 		list_del(&cap->session_caps);
@@ -1590,6 +1600,11 @@ void ceph_send_cap_releases(struct ceph_mds_client *mdsc,
 		ceph_put_cap(mdsc, cap);
 
 		if (le32_to_cpu(head->num) == CEPH_CAPS_PER_RELEASE) {
+			// Append cap_barrier field
+			cap_barrier = msg->front.iov_base + msg->front.iov_len;
+			*cap_barrier = barrier;
+			msg->front.iov_len += sizeof(*cap_barrier);
+
 			msg->hdr.front_len = cpu_to_le32(msg->front.iov_len);
 			dout("send_cap_releases mds%d %p\n", session->s_mds, msg);
 			ceph_con_send(&session->s_con, msg);
@@ -1605,6 +1620,11 @@ void ceph_send_cap_releases(struct ceph_mds_client *mdsc,
 	spin_unlock(&session->s_cap_lock);
 
 	if (msg) {
+		// Append cap_barrier field
+		cap_barrier = msg->front.iov_base + msg->front.iov_len;
+		*cap_barrier = barrier;
+		msg->front.iov_len += sizeof(*cap_barrier);
+
 		msg->hdr.front_len = cpu_to_le32(msg->front.iov_len);
 		dout("send_cap_releases mds%d %p\n", session->s_mds, msg);
 		ceph_con_send(&session->s_con, msg);
diff --git a/fs/ceph/mds_client.h b/fs/ceph/mds_client.h
index 3e67dd2169fa..db57ae98ed34 100644
--- a/fs/ceph/mds_client.h
+++ b/fs/ceph/mds_client.h
@@ -106,10 +106,13 @@ struct ceph_mds_reply_info_parsed {
 
 /*
  * cap releases are batched and sent to the MDS en masse.
+ *
+ * Account for per-message overhead of mds_cap_release header
+ * and __le32 for osd epoch barrier trailing field.
  */
-#define CEPH_CAPS_PER_RELEASE ((PAGE_SIZE -			\
+#define CEPH_CAPS_PER_RELEASE ((PAGE_SIZE - sizeof(u32) -		\
 				sizeof(struct ceph_mds_cap_release)) /	\
-			       sizeof(struct ceph_mds_cap_item))
+			        sizeof(struct ceph_mds_cap_item))
 
 
 /*
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v8 6/7] Revert "ceph: SetPageError() for writeback pages if writepages fails"
  2017-04-17 16:42 [PATCH v8 0/7] ceph: implement -ENOSPC handling in cephfs Jeff Layton
                   ` (4 preceding siblings ...)
  2017-04-17 16:42 ` [PATCH v8 5/7] ceph: handle epoch barriers in cap messages Jeff Layton
@ 2017-04-17 16:42 ` Jeff Layton
  2017-04-17 16:42 ` [PATCH v8 7/7] ceph: when seeing write errors on an inode, switch to sync writes Jeff Layton
  6 siblings, 0 replies; 13+ messages in thread
From: Jeff Layton @ 2017-04-17 16:42 UTC (permalink / raw)
  To: idryomov, zyan, sage; +Cc: jspray, ceph-devel

This reverts commit b109eec6f4332bd517e2f41e207037c4b9065094.

If I'm filling up a filesystem with this sort of command:

    $ dd if=/dev/urandom of=/mnt/cephfs/fillfile bs=2M oflag=sync

...then I'll eventually get back EIO on a write. Further calls
will give us ENOSPC.

I'm not sure what prompted this change, but I don't think it's what we
want to do. If writepages failed, we will have already set the mapping
error appropriately, and that's what gets reported by fsync() or
close().

__filemap_fdatawait_range however, does this:

	wait_on_page_writeback(page);
	if (TestClearPageError(page))
		ret = -EIO;

...and that -EIO ends up trumping the mapping's error if one exists.

When writepages fails, we only want to set the error in the mapping,
and not flag the individual pages.

Reviewed-by: "Yan, Zheng” <zyan@redhat.com>
Signed-off-by: Jeff Layton <jlayton@redhat.com>
---
 fs/ceph/addr.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c
index 7e3fae334620..6cdf94459ac4 100644
--- a/fs/ceph/addr.c
+++ b/fs/ceph/addr.c
@@ -703,9 +703,6 @@ static void writepages_finish(struct ceph_osd_request *req)
 				clear_bdi_congested(&fsc->backing_dev_info,
 						    BLK_RW_ASYNC);
 
-			if (rc < 0)
-				SetPageError(page);
-
 			ceph_put_snap_context(page_snap_context(page));
 			page->private = 0;
 			ClearPagePrivate(page);
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v8 7/7] ceph: when seeing write errors on an inode, switch to sync writes
  2017-04-17 16:42 [PATCH v8 0/7] ceph: implement -ENOSPC handling in cephfs Jeff Layton
                   ` (5 preceding siblings ...)
  2017-04-17 16:42 ` [PATCH v8 6/7] Revert "ceph: SetPageError() for writeback pages if writepages fails" Jeff Layton
@ 2017-04-17 16:42 ` Jeff Layton
  6 siblings, 0 replies; 13+ messages in thread
From: Jeff Layton @ 2017-04-17 16:42 UTC (permalink / raw)
  To: idryomov, zyan, sage; +Cc: jspray, ceph-devel

Currently, we don't have a real feedback mechanism in place for when we
start seeing buffered writeback errors. If writeback is failing, there
is nothing that prevents an application from continuing to dirty pages
that aren't being cleaned.

In the event that we're seeing write errors of any sort occur on an
inode, have the callback set a flag to force further writes to be
synchronous. When the next write succeeds, clear the flag to allow
buffered writeback to continue.

Since this is just a hint to the write submission mechanism, we only
take the i_ceph_lock when a lockless check shows that the flag needs to
be changed.

Reviewed-by: "Yan, Zheng” <zyan@redhat.com>
Signed-off-by: Jeff Layton <jlayton@redhat.com>
---
 fs/ceph/addr.c  |  6 +++++-
 fs/ceph/file.c  | 31 ++++++++++++++++++-------------
 fs/ceph/super.h | 26 ++++++++++++++++++++++++++
 3 files changed, 49 insertions(+), 14 deletions(-)

diff --git a/fs/ceph/addr.c b/fs/ceph/addr.c
index 6cdf94459ac4..e253102b43cd 100644
--- a/fs/ceph/addr.c
+++ b/fs/ceph/addr.c
@@ -670,8 +670,12 @@ static void writepages_finish(struct ceph_osd_request *req)
 	bool remove_page;
 
 	dout("writepages_finish %p rc %d\n", inode, rc);
-	if (rc < 0)
+	if (rc < 0) {
 		mapping_set_error(mapping, rc);
+		ceph_set_error_write(ci);
+	} else {
+		ceph_clear_error_write(ci);
+	}
 
 	/*
 	 * We lost the cache cap, need to truncate the page before
diff --git a/fs/ceph/file.c b/fs/ceph/file.c
index cff35a1ff53c..0480492aa349 100644
--- a/fs/ceph/file.c
+++ b/fs/ceph/file.c
@@ -1020,19 +1020,22 @@ ceph_sync_write(struct kiocb *iocb, struct iov_iter *from, loff_t pos,
 
 out:
 		ceph_osdc_put_request(req);
-		if (ret == 0) {
-			pos += len;
-			written += len;
-
-			if (pos > i_size_read(inode)) {
-				check_caps = ceph_inode_set_size(inode, pos);
-				if (check_caps)
-					ceph_check_caps(ceph_inode(inode),
-							CHECK_CAPS_AUTHONLY,
-							NULL);
-			}
-		} else
+		if (ret != 0) {
+			ceph_set_error_write(ci);
 			break;
+		}
+
+		ceph_clear_error_write(ci);
+		pos += len;
+		written += len;
+		if (pos > i_size_read(inode)) {
+			check_caps = ceph_inode_set_size(inode, pos);
+			if (check_caps)
+				ceph_check_caps(ceph_inode(inode),
+						CHECK_CAPS_AUTHONLY,
+						NULL);
+		}
+
 	}
 
 	if (ret != -EOLDSNAPC && written > 0) {
@@ -1238,6 +1241,7 @@ static ssize_t ceph_write_iter(struct kiocb *iocb, struct iov_iter *from)
 	}
 
 retry_snap:
+	/* FIXME: not complete since it doesn't account for being at quota */
 	if (ceph_osdmap_flag(osdc, CEPH_OSDMAP_FULL)) {
 		err = -ENOSPC;
 		goto out;
@@ -1259,7 +1263,8 @@ static ssize_t ceph_write_iter(struct kiocb *iocb, struct iov_iter *from)
 	     inode, ceph_vinop(inode), pos, count, ceph_cap_string(got));
 
 	if ((got & (CEPH_CAP_FILE_BUFFER|CEPH_CAP_FILE_LAZYIO)) == 0 ||
-	    (iocb->ki_flags & IOCB_DIRECT) || (fi->flags & CEPH_F_SYNC)) {
+	    (iocb->ki_flags & IOCB_DIRECT) || (fi->flags & CEPH_F_SYNC) ||
+	    (ci->i_ceph_flags & CEPH_I_ERROR_WRITE)) {
 		struct ceph_snap_context *snapc;
 		struct iov_iter data;
 		inode_unlock(inode);
diff --git a/fs/ceph/super.h b/fs/ceph/super.h
index c68e6a045fb9..7334ee86b9e8 100644
--- a/fs/ceph/super.h
+++ b/fs/ceph/super.h
@@ -474,6 +474,32 @@ static inline struct inode *ceph_find_inode(struct super_block *sb,
 #define CEPH_I_CAP_DROPPED	(1 << 8)  /* caps were forcibly dropped */
 #define CEPH_I_KICK_FLUSH	(1 << 9)  /* kick flushing caps */
 #define CEPH_I_FLUSH_SNAPS	(1 << 10) /* need flush snapss */
+#define CEPH_I_ERROR_WRITE	(1 << 11) /* have seen write errors */
+
+/*
+ * We set the ERROR_WRITE bit when we start seeing write errors on an inode
+ * and then clear it when they start succeeding. Note that we do a lockless
+ * check first, and only take the lock if it looks like it needs to be changed.
+ * The write submission code just takes this as a hint, so we're not too
+ * worried if a few slip through in either direction.
+ */
+static inline void ceph_set_error_write(struct ceph_inode_info *ci)
+{
+	if (!(READ_ONCE(ci->i_ceph_flags) & CEPH_I_ERROR_WRITE)) {
+		spin_lock(&ci->i_ceph_lock);
+		ci->i_ceph_flags |= CEPH_I_ERROR_WRITE;
+		spin_unlock(&ci->i_ceph_lock);
+	}
+}
+
+static inline void ceph_clear_error_write(struct ceph_inode_info *ci)
+{
+	if (READ_ONCE(ci->i_ceph_flags) & CEPH_I_ERROR_WRITE) {
+		spin_lock(&ci->i_ceph_lock);
+		ci->i_ceph_flags &= ~CEPH_I_ERROR_WRITE;
+		spin_unlock(&ci->i_ceph_lock);
+	}
+}
 
 static inline void __ceph_dir_set_complete(struct ceph_inode_info *ci,
 					   long long release_count,
-- 
2.9.3


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH v8 4/7] libceph: add an epoch_barrier field to struct ceph_osd_client
  2017-04-17 16:42 ` [PATCH v8 4/7] libceph: add an epoch_barrier field to struct ceph_osd_client Jeff Layton
@ 2017-04-18 12:19   ` Jeff Layton
  2017-04-18 12:38     ` John Spray
  2017-04-18 13:09     ` Ilya Dryomov
  0 siblings, 2 replies; 13+ messages in thread
From: Jeff Layton @ 2017-04-18 12:19 UTC (permalink / raw)
  To: idryomov, zyan, sage; +Cc: jspray, ceph-devel

On Mon, 2017-04-17 at 12:42 -0400, Jeff Layton wrote:
> Cephfs can get cap update requests that contain a new epoch barrier in
> them. When that happens we want to pause all OSD traffic until the right
> map epoch arrives.
> 
> Add an epoch_barrier field to ceph_osd_client that is protected by the
> osdc->lock rwsem. When the barrier is set, and the current OSD map
> epoch is below that, pause the request target when submitting the
> request or when revisiting it. Add a way for upper layers (cephfs)
> to update the epoch_barrier as well.
> 
> If we get a new map, compare the new epoch against the barrier before
> kicking requests and request another map if the map epoch is still lower
> than the one we want.
> 
> If we get a map with a full pool, or at quota condition, then set the
> barrier to the current epoch value.
> 
> Reviewed-by: "Yan, Zheng” <zyan@redhat.com>
> Signed-off-by: Jeff Layton <jlayton@redhat.com>
> Reviewed-by: Ilya Dryomov <idryomov@gmail.com>
> ---
>  include/linux/ceph/osd_client.h |  2 ++
>  net/ceph/debugfs.c              |  3 +-
>  net/ceph/osd_client.c           | 76 ++++++++++++++++++++++++++++++++++++-----
>  3 files changed, 72 insertions(+), 9 deletions(-)
> 
> diff --git a/include/linux/ceph/osd_client.h b/include/linux/ceph/osd_client.h
> index 8cf644197b1a..85650b415e73 100644
> --- a/include/linux/ceph/osd_client.h
> +++ b/include/linux/ceph/osd_client.h
> @@ -267,6 +267,7 @@ struct ceph_osd_client {
>  	struct rb_root         osds;          /* osds */
>  	struct list_head       osd_lru;       /* idle osds */
>  	spinlock_t             osd_lru_lock;
> +	u32		       epoch_barrier;
>  	struct ceph_osd        homeless_osd;
>  	atomic64_t             last_tid;      /* tid of last request */
>  	u64                    last_linger_id;
> @@ -305,6 +306,7 @@ extern void ceph_osdc_handle_reply(struct ceph_osd_client *osdc,
>  				   struct ceph_msg *msg);
>  extern void ceph_osdc_handle_map(struct ceph_osd_client *osdc,
>  				 struct ceph_msg *msg);
> +void ceph_osdc_update_epoch_barrier(struct ceph_osd_client *osdc, u32 eb);
>  
>  extern void osd_req_op_init(struct ceph_osd_request *osd_req,
>  			    unsigned int which, u16 opcode, u32 flags);
> diff --git a/net/ceph/debugfs.c b/net/ceph/debugfs.c
> index d7e63a4f5578..71ba13927b3d 100644
> --- a/net/ceph/debugfs.c
> +++ b/net/ceph/debugfs.c
> @@ -62,7 +62,8 @@ static int osdmap_show(struct seq_file *s, void *p)
>  		return 0;
>  
>  	down_read(&osdc->lock);
> -	seq_printf(s, "epoch %d flags 0x%x\n", map->epoch, map->flags);
> +	seq_printf(s, "epoch %u barrier %u flags 0x%x\n", map->epoch,
> +			osdc->epoch_barrier, map->flags);
>  
>  	for (n = rb_first(&map->pg_pools); n; n = rb_next(n)) {
>  		struct ceph_pg_pool_info *pi =
> diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
> index 55b7585ccefd..beeac4f39aa5 100644
> --- a/net/ceph/osd_client.c
> +++ b/net/ceph/osd_client.c
> @@ -1298,8 +1298,9 @@ static bool target_should_be_paused(struct ceph_osd_client *osdc,
>  		       __pool_full(pi);
>  
>  	WARN_ON(pi->id != t->base_oloc.pool);
> -	return (t->flags & CEPH_OSD_FLAG_READ && pauserd) ||
> -	       (t->flags & CEPH_OSD_FLAG_WRITE && pausewr);
> +	return ((t->flags & CEPH_OSD_FLAG_READ) && pauserd) ||
> +	       ((t->flags & CEPH_OSD_FLAG_WRITE) && pausewr) ||
> +	       (osdc->osdmap->epoch < osdc->epoch_barrier);
>  }
>  
>  enum calc_target_result {
> @@ -1654,8 +1655,13 @@ static void __submit_request(struct ceph_osd_request *req, bool wrlocked)
>  		goto promote;
>  	}
>  
> -	if ((req->r_flags & CEPH_OSD_FLAG_WRITE) &&
> -	    ceph_osdmap_flag(osdc, CEPH_OSDMAP_PAUSEWR)) {
> +	if (osdc->osdmap->epoch < osdc->epoch_barrier) {
> +		dout("req %p epoch %u barrier %u\n", req, osdc->osdmap->epoch,
> +		     osdc->epoch_barrier);
> +		req->r_t.paused = true;
> +		maybe_request_map(osdc);
> +	} else if ((req->r_flags & CEPH_OSD_FLAG_WRITE) &&
> +		   ceph_osdmap_flag(osdc, CEPH_OSDMAP_PAUSEWR)) {
>  		dout("req %p pausewr\n", req);
>  		req->r_t.paused = true;
>  		maybe_request_map(osdc);
> @@ -1809,17 +1815,48 @@ static void abort_request(struct ceph_osd_request *req, int err)
>  
>  /*
>   * Drop all pending requests that are stalled waiting on a full condition to
> - * clear, and complete them with ENOSPC as the return code.
> + * clear, and complete them with ENOSPC as the return code. Set the
> + * osdc->epoch_barrier to the latest map epoch that we've seen if any were
> + * cancelled.
>   */
>  static void ceph_osdc_abort_on_full(struct ceph_osd_client *osdc)
>  {
>  	struct rb_node *n;
> +	bool victims = false;
>  
>  	dout("enter abort_on_full\n");
>  
>  	if (!ceph_osdmap_flag(osdc, CEPH_OSDMAP_FULL) && !have_pool_full(osdc))
>  		goto out;
>  
> +	/* Scan list and see if there is anything to abort */
> +	for (n = rb_first(&osdc->osds); n; n = rb_next(n)) {
> +		struct ceph_osd *osd = rb_entry(n, struct ceph_osd, o_node);
> +		struct rb_node *m;
> +
> +		m = rb_first(&osd->o_requests);
> +		while (m) {
> +			struct ceph_osd_request *req = rb_entry(m,
> +					struct ceph_osd_request, r_node);
> +			m = rb_next(m);
> +
> +			if (req->r_abort_on_full) {
> +				victims = true;
> +				break;
> +			}
> +		}
> +		if (victims)
> +			break;
> +	}
> +
> +	if (!victims)
> +		goto out;
> +
> +	/*
> +	 * Update the barrier to current epoch since we know we have some
> +	 * calls to be aborted in the tree.
> +	 */
> +	osdc->epoch_barrier = osdc->osdmap->epoch;

Erm...now that I think about it even more...

Is it possible we can end up with the eb going backward here? Suppose
we get a MDS cap message with a later epoch barrier, and then a map
update that is not quite to the barrier yet.

I think we probably want to only set it if it's newer than what's
there. So this should probably read something like:

        if (osdc->osdmap->epoch > osdc->epoch_barrier)
                osdc->epoch_barrier = osdc->osdmap->epoch;

If no one objects, I'll go ahead and make this change in the testing
branch without a full re-post to the list.

>  	for (n = rb_first(&osdc->osds); n; n = rb_next(n)) {
>  		struct ceph_osd *osd = rb_entry(n, struct ceph_osd, o_node);
>  		struct rb_node *m;
> @@ -1832,12 +1869,13 @@ static void ceph_osdc_abort_on_full(struct ceph_osd_client *osdc)
>  
>  			if (req->r_abort_on_full &&
>  			    (ceph_osdmap_flag(osdc, CEPH_OSDMAP_FULL) ||
> -			     pool_full(osdc, req->r_t.target_oloc.pool)))
> +			     pool_full(osdc, req->r_t.target_oloc.pool))) {
>  				abort_request(req, -ENOSPC);
> +			}
>  		}
>  	}
>  out:
> -	dout("return abort_on_full\n");
> +	dout("return abort_on_full barrier=%u\n", osdc->epoch_barrier);
>  }
>  
>  static void check_pool_dne(struct ceph_osd_request *req)
> @@ -3293,7 +3331,8 @@ void ceph_osdc_handle_map(struct ceph_osd_client *osdc, struct ceph_msg *msg)
>  	pausewr = ceph_osdmap_flag(osdc, CEPH_OSDMAP_PAUSEWR) ||
>  		  ceph_osdmap_flag(osdc, CEPH_OSDMAP_FULL) ||
>  		  have_pool_full(osdc);
> -	if (was_pauserd || was_pausewr || pauserd || pausewr)
> +	if (was_pauserd || was_pausewr || pauserd || pausewr ||
> +	    osdc->osdmap->epoch < osdc->epoch_barrier)
>  		maybe_request_map(osdc);
>  
>  	kick_requests(osdc, &need_resend, &need_resend_linger);
> @@ -3311,6 +3350,27 @@ void ceph_osdc_handle_map(struct ceph_osd_client *osdc, struct ceph_msg *msg)
>  	up_write(&osdc->lock);
>  }
>  
> +void ceph_osdc_update_epoch_barrier(struct ceph_osd_client *osdc, u32 eb)
> +{
> +	down_read(&osdc->lock);
> +	if (unlikely(eb > osdc->epoch_barrier)) {
> +		up_read(&osdc->lock);
> +		down_write(&osdc->lock);
> +		if (likely(eb > osdc->epoch_barrier)) {
> +			dout("updating epoch_barrier from %u to %u\n",
> +					osdc->epoch_barrier, eb);
> +			osdc->epoch_barrier = eb;
> +			/* Request map if we're not to the barrier yet */
> +			if (eb > osdc->osdmap->epoch)
> +				maybe_request_map(osdc);
> +		}
> +		up_write(&osdc->lock);
> +	} else {
> +		up_read(&osdc->lock);
> +	}
> +}
> +EXPORT_SYMBOL(ceph_osdc_update_epoch_barrier);
> +
>  /*
>   * Resubmit requests pending on the given osd.
>   */

-- 
Jeff Layton <jlayton@redhat.com>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v8 4/7] libceph: add an epoch_barrier field to struct ceph_osd_client
  2017-04-18 12:19   ` Jeff Layton
@ 2017-04-18 12:38     ` John Spray
  2017-04-18 13:09     ` Ilya Dryomov
  1 sibling, 0 replies; 13+ messages in thread
From: John Spray @ 2017-04-18 12:38 UTC (permalink / raw)
  To: Jeff Layton; +Cc: Ilya Dryomov, 严正, Sage Weil, Ceph Development

On Tue, Apr 18, 2017 at 1:19 PM, Jeff Layton <jlayton@redhat.com> wrote:
> On Mon, 2017-04-17 at 12:42 -0400, Jeff Layton wrote:
>> Cephfs can get cap update requests that contain a new epoch barrier in
>> them. When that happens we want to pause all OSD traffic until the right
>> map epoch arrives.
>>
>> Add an epoch_barrier field to ceph_osd_client that is protected by the
>> osdc->lock rwsem. When the barrier is set, and the current OSD map
>> epoch is below that, pause the request target when submitting the
>> request or when revisiting it. Add a way for upper layers (cephfs)
>> to update the epoch_barrier as well.
>>
>> If we get a new map, compare the new epoch against the barrier before
>> kicking requests and request another map if the map epoch is still lower
>> than the one we want.
>>
>> If we get a map with a full pool, or at quota condition, then set the
>> barrier to the current epoch value.
>>
>> Reviewed-by: "Yan, Zheng” <zyan@redhat.com>
>> Signed-off-by: Jeff Layton <jlayton@redhat.com>
>> Reviewed-by: Ilya Dryomov <idryomov@gmail.com>
>> ---
>>  include/linux/ceph/osd_client.h |  2 ++
>>  net/ceph/debugfs.c              |  3 +-
>>  net/ceph/osd_client.c           | 76 ++++++++++++++++++++++++++++++++++++-----
>>  3 files changed, 72 insertions(+), 9 deletions(-)
>>
>> diff --git a/include/linux/ceph/osd_client.h b/include/linux/ceph/osd_client.h
>> index 8cf644197b1a..85650b415e73 100644
>> --- a/include/linux/ceph/osd_client.h
>> +++ b/include/linux/ceph/osd_client.h
>> @@ -267,6 +267,7 @@ struct ceph_osd_client {
>>       struct rb_root         osds;          /* osds */
>>       struct list_head       osd_lru;       /* idle osds */
>>       spinlock_t             osd_lru_lock;
>> +     u32                    epoch_barrier;
>>       struct ceph_osd        homeless_osd;
>>       atomic64_t             last_tid;      /* tid of last request */
>>       u64                    last_linger_id;
>> @@ -305,6 +306,7 @@ extern void ceph_osdc_handle_reply(struct ceph_osd_client *osdc,
>>                                  struct ceph_msg *msg);
>>  extern void ceph_osdc_handle_map(struct ceph_osd_client *osdc,
>>                                struct ceph_msg *msg);
>> +void ceph_osdc_update_epoch_barrier(struct ceph_osd_client *osdc, u32 eb);
>>
>>  extern void osd_req_op_init(struct ceph_osd_request *osd_req,
>>                           unsigned int which, u16 opcode, u32 flags);
>> diff --git a/net/ceph/debugfs.c b/net/ceph/debugfs.c
>> index d7e63a4f5578..71ba13927b3d 100644
>> --- a/net/ceph/debugfs.c
>> +++ b/net/ceph/debugfs.c
>> @@ -62,7 +62,8 @@ static int osdmap_show(struct seq_file *s, void *p)
>>               return 0;
>>
>>       down_read(&osdc->lock);
>> -     seq_printf(s, "epoch %d flags 0x%x\n", map->epoch, map->flags);
>> +     seq_printf(s, "epoch %u barrier %u flags 0x%x\n", map->epoch,
>> +                     osdc->epoch_barrier, map->flags);
>>
>>       for (n = rb_first(&map->pg_pools); n; n = rb_next(n)) {
>>               struct ceph_pg_pool_info *pi =
>> diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
>> index 55b7585ccefd..beeac4f39aa5 100644
>> --- a/net/ceph/osd_client.c
>> +++ b/net/ceph/osd_client.c
>> @@ -1298,8 +1298,9 @@ static bool target_should_be_paused(struct ceph_osd_client *osdc,
>>                      __pool_full(pi);
>>
>>       WARN_ON(pi->id != t->base_oloc.pool);
>> -     return (t->flags & CEPH_OSD_FLAG_READ && pauserd) ||
>> -            (t->flags & CEPH_OSD_FLAG_WRITE && pausewr);
>> +     return ((t->flags & CEPH_OSD_FLAG_READ) && pauserd) ||
>> +            ((t->flags & CEPH_OSD_FLAG_WRITE) && pausewr) ||
>> +            (osdc->osdmap->epoch < osdc->epoch_barrier);
>>  }
>>
>>  enum calc_target_result {
>> @@ -1654,8 +1655,13 @@ static void __submit_request(struct ceph_osd_request *req, bool wrlocked)
>>               goto promote;
>>       }
>>
>> -     if ((req->r_flags & CEPH_OSD_FLAG_WRITE) &&
>> -         ceph_osdmap_flag(osdc, CEPH_OSDMAP_PAUSEWR)) {
>> +     if (osdc->osdmap->epoch < osdc->epoch_barrier) {
>> +             dout("req %p epoch %u barrier %u\n", req, osdc->osdmap->epoch,
>> +                  osdc->epoch_barrier);
>> +             req->r_t.paused = true;
>> +             maybe_request_map(osdc);
>> +     } else if ((req->r_flags & CEPH_OSD_FLAG_WRITE) &&
>> +                ceph_osdmap_flag(osdc, CEPH_OSDMAP_PAUSEWR)) {
>>               dout("req %p pausewr\n", req);
>>               req->r_t.paused = true;
>>               maybe_request_map(osdc);
>> @@ -1809,17 +1815,48 @@ static void abort_request(struct ceph_osd_request *req, int err)
>>
>>  /*
>>   * Drop all pending requests that are stalled waiting on a full condition to
>> - * clear, and complete them with ENOSPC as the return code.
>> + * clear, and complete them with ENOSPC as the return code. Set the
>> + * osdc->epoch_barrier to the latest map epoch that we've seen if any were
>> + * cancelled.
>>   */
>>  static void ceph_osdc_abort_on_full(struct ceph_osd_client *osdc)
>>  {
>>       struct rb_node *n;
>> +     bool victims = false;
>>
>>       dout("enter abort_on_full\n");
>>
>>       if (!ceph_osdmap_flag(osdc, CEPH_OSDMAP_FULL) && !have_pool_full(osdc))
>>               goto out;
>>
>> +     /* Scan list and see if there is anything to abort */
>> +     for (n = rb_first(&osdc->osds); n; n = rb_next(n)) {
>> +             struct ceph_osd *osd = rb_entry(n, struct ceph_osd, o_node);
>> +             struct rb_node *m;
>> +
>> +             m = rb_first(&osd->o_requests);
>> +             while (m) {
>> +                     struct ceph_osd_request *req = rb_entry(m,
>> +                                     struct ceph_osd_request, r_node);
>> +                     m = rb_next(m);
>> +
>> +                     if (req->r_abort_on_full) {
>> +                             victims = true;
>> +                             break;
>> +                     }
>> +             }
>> +             if (victims)
>> +                     break;
>> +     }
>> +
>> +     if (!victims)
>> +             goto out;
>> +
>> +     /*
>> +      * Update the barrier to current epoch since we know we have some
>> +      * calls to be aborted in the tree.
>> +      */
>> +     osdc->epoch_barrier = osdc->osdmap->epoch;
>
> Erm...now that I think about it even more...
>
> Is it possible we can end up with the eb going backward here? Suppose
> we get a MDS cap message with a later epoch barrier, and then a map
> update that is not quite to the barrier yet.
>
> I think we probably want to only set it if it's newer than what's
> there. So this should probably read something like:
>
>         if (osdc->osdmap->epoch > osdc->epoch_barrier)
>                 osdc->epoch_barrier = osdc->osdmap->epoch;
>
> If no one objects, I'll go ahead and make this change in the testing
> branch without a full re-post to the list.

Yes indeed -- the userspace client does the same check inside
Objecter::set_epoch_barrier.

John

>>       for (n = rb_first(&osdc->osds); n; n = rb_next(n)) {
>>               struct ceph_osd *osd = rb_entry(n, struct ceph_osd, o_node);
>>               struct rb_node *m;
>> @@ -1832,12 +1869,13 @@ static void ceph_osdc_abort_on_full(struct ceph_osd_client *osdc)
>>
>>                       if (req->r_abort_on_full &&
>>                           (ceph_osdmap_flag(osdc, CEPH_OSDMAP_FULL) ||
>> -                          pool_full(osdc, req->r_t.target_oloc.pool)))
>> +                          pool_full(osdc, req->r_t.target_oloc.pool))) {
>>                               abort_request(req, -ENOSPC);
>> +                     }
>>               }
>>       }
>>  out:
>> -     dout("return abort_on_full\n");
>> +     dout("return abort_on_full barrier=%u\n", osdc->epoch_barrier);
>>  }
>>
>>  static void check_pool_dne(struct ceph_osd_request *req)
>> @@ -3293,7 +3331,8 @@ void ceph_osdc_handle_map(struct ceph_osd_client *osdc, struct ceph_msg *msg)
>>       pausewr = ceph_osdmap_flag(osdc, CEPH_OSDMAP_PAUSEWR) ||
>>                 ceph_osdmap_flag(osdc, CEPH_OSDMAP_FULL) ||
>>                 have_pool_full(osdc);
>> -     if (was_pauserd || was_pausewr || pauserd || pausewr)
>> +     if (was_pauserd || was_pausewr || pauserd || pausewr ||
>> +         osdc->osdmap->epoch < osdc->epoch_barrier)
>>               maybe_request_map(osdc);
>>
>>       kick_requests(osdc, &need_resend, &need_resend_linger);
>> @@ -3311,6 +3350,27 @@ void ceph_osdc_handle_map(struct ceph_osd_client *osdc, struct ceph_msg *msg)
>>       up_write(&osdc->lock);
>>  }
>>
>> +void ceph_osdc_update_epoch_barrier(struct ceph_osd_client *osdc, u32 eb)
>> +{
>> +     down_read(&osdc->lock);
>> +     if (unlikely(eb > osdc->epoch_barrier)) {
>> +             up_read(&osdc->lock);
>> +             down_write(&osdc->lock);
>> +             if (likely(eb > osdc->epoch_barrier)) {
>> +                     dout("updating epoch_barrier from %u to %u\n",
>> +                                     osdc->epoch_barrier, eb);
>> +                     osdc->epoch_barrier = eb;
>> +                     /* Request map if we're not to the barrier yet */
>> +                     if (eb > osdc->osdmap->epoch)
>> +                             maybe_request_map(osdc);
>> +             }
>> +             up_write(&osdc->lock);
>> +     } else {
>> +             up_read(&osdc->lock);
>> +     }
>> +}
>> +EXPORT_SYMBOL(ceph_osdc_update_epoch_barrier);
>> +
>>  /*
>>   * Resubmit requests pending on the given osd.
>>   */
>
> --
> Jeff Layton <jlayton@redhat.com>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v8 4/7] libceph: add an epoch_barrier field to struct ceph_osd_client
  2017-04-18 12:19   ` Jeff Layton
  2017-04-18 12:38     ` John Spray
@ 2017-04-18 13:09     ` Ilya Dryomov
  2017-04-18 13:24       ` Jeff Layton
  1 sibling, 1 reply; 13+ messages in thread
From: Ilya Dryomov @ 2017-04-18 13:09 UTC (permalink / raw)
  To: Jeff Layton; +Cc: Yan, Zheng, Sage Weil, John Spray, Ceph Development

On Tue, Apr 18, 2017 at 2:19 PM, Jeff Layton <jlayton@redhat.com> wrote:
> On Mon, 2017-04-17 at 12:42 -0400, Jeff Layton wrote:
>> Cephfs can get cap update requests that contain a new epoch barrier in
>> them. When that happens we want to pause all OSD traffic until the right
>> map epoch arrives.
>>
>> Add an epoch_barrier field to ceph_osd_client that is protected by the
>> osdc->lock rwsem. When the barrier is set, and the current OSD map
>> epoch is below that, pause the request target when submitting the
>> request or when revisiting it. Add a way for upper layers (cephfs)
>> to update the epoch_barrier as well.
>>
>> If we get a new map, compare the new epoch against the barrier before
>> kicking requests and request another map if the map epoch is still lower
>> than the one we want.
>>
>> If we get a map with a full pool, or at quota condition, then set the
>> barrier to the current epoch value.
>>
>> Reviewed-by: "Yan, Zheng” <zyan@redhat.com>
>> Signed-off-by: Jeff Layton <jlayton@redhat.com>
>> Reviewed-by: Ilya Dryomov <idryomov@gmail.com>
>> ---
>>  include/linux/ceph/osd_client.h |  2 ++
>>  net/ceph/debugfs.c              |  3 +-
>>  net/ceph/osd_client.c           | 76 ++++++++++++++++++++++++++++++++++++-----
>>  3 files changed, 72 insertions(+), 9 deletions(-)
>>
>> diff --git a/include/linux/ceph/osd_client.h b/include/linux/ceph/osd_client.h
>> index 8cf644197b1a..85650b415e73 100644
>> --- a/include/linux/ceph/osd_client.h
>> +++ b/include/linux/ceph/osd_client.h
>> @@ -267,6 +267,7 @@ struct ceph_osd_client {
>>       struct rb_root         osds;          /* osds */
>>       struct list_head       osd_lru;       /* idle osds */
>>       spinlock_t             osd_lru_lock;
>> +     u32                    epoch_barrier;
>>       struct ceph_osd        homeless_osd;
>>       atomic64_t             last_tid;      /* tid of last request */
>>       u64                    last_linger_id;
>> @@ -305,6 +306,7 @@ extern void ceph_osdc_handle_reply(struct ceph_osd_client *osdc,
>>                                  struct ceph_msg *msg);
>>  extern void ceph_osdc_handle_map(struct ceph_osd_client *osdc,
>>                                struct ceph_msg *msg);
>> +void ceph_osdc_update_epoch_barrier(struct ceph_osd_client *osdc, u32 eb);
>>
>>  extern void osd_req_op_init(struct ceph_osd_request *osd_req,
>>                           unsigned int which, u16 opcode, u32 flags);
>> diff --git a/net/ceph/debugfs.c b/net/ceph/debugfs.c
>> index d7e63a4f5578..71ba13927b3d 100644
>> --- a/net/ceph/debugfs.c
>> +++ b/net/ceph/debugfs.c
>> @@ -62,7 +62,8 @@ static int osdmap_show(struct seq_file *s, void *p)
>>               return 0;
>>
>>       down_read(&osdc->lock);
>> -     seq_printf(s, "epoch %d flags 0x%x\n", map->epoch, map->flags);
>> +     seq_printf(s, "epoch %u barrier %u flags 0x%x\n", map->epoch,
>> +                     osdc->epoch_barrier, map->flags);
>>
>>       for (n = rb_first(&map->pg_pools); n; n = rb_next(n)) {
>>               struct ceph_pg_pool_info *pi =
>> diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
>> index 55b7585ccefd..beeac4f39aa5 100644
>> --- a/net/ceph/osd_client.c
>> +++ b/net/ceph/osd_client.c
>> @@ -1298,8 +1298,9 @@ static bool target_should_be_paused(struct ceph_osd_client *osdc,
>>                      __pool_full(pi);
>>
>>       WARN_ON(pi->id != t->base_oloc.pool);
>> -     return (t->flags & CEPH_OSD_FLAG_READ && pauserd) ||
>> -            (t->flags & CEPH_OSD_FLAG_WRITE && pausewr);
>> +     return ((t->flags & CEPH_OSD_FLAG_READ) && pauserd) ||
>> +            ((t->flags & CEPH_OSD_FLAG_WRITE) && pausewr) ||
>> +            (osdc->osdmap->epoch < osdc->epoch_barrier);
>>  }
>>
>>  enum calc_target_result {
>> @@ -1654,8 +1655,13 @@ static void __submit_request(struct ceph_osd_request *req, bool wrlocked)
>>               goto promote;
>>       }
>>
>> -     if ((req->r_flags & CEPH_OSD_FLAG_WRITE) &&
>> -         ceph_osdmap_flag(osdc, CEPH_OSDMAP_PAUSEWR)) {
>> +     if (osdc->osdmap->epoch < osdc->epoch_barrier) {
>> +             dout("req %p epoch %u barrier %u\n", req, osdc->osdmap->epoch,
>> +                  osdc->epoch_barrier);
>> +             req->r_t.paused = true;
>> +             maybe_request_map(osdc);
>> +     } else if ((req->r_flags & CEPH_OSD_FLAG_WRITE) &&
>> +                ceph_osdmap_flag(osdc, CEPH_OSDMAP_PAUSEWR)) {
>>               dout("req %p pausewr\n", req);
>>               req->r_t.paused = true;
>>               maybe_request_map(osdc);
>> @@ -1809,17 +1815,48 @@ static void abort_request(struct ceph_osd_request *req, int err)
>>
>>  /*
>>   * Drop all pending requests that are stalled waiting on a full condition to
>> - * clear, and complete them with ENOSPC as the return code.
>> + * clear, and complete them with ENOSPC as the return code. Set the
>> + * osdc->epoch_barrier to the latest map epoch that we've seen if any were
>> + * cancelled.
>>   */
>>  static void ceph_osdc_abort_on_full(struct ceph_osd_client *osdc)
>>  {
>>       struct rb_node *n;
>> +     bool victims = false;
>>
>>       dout("enter abort_on_full\n");
>>
>>       if (!ceph_osdmap_flag(osdc, CEPH_OSDMAP_FULL) && !have_pool_full(osdc))
>>               goto out;
>>
>> +     /* Scan list and see if there is anything to abort */
>> +     for (n = rb_first(&osdc->osds); n; n = rb_next(n)) {
>> +             struct ceph_osd *osd = rb_entry(n, struct ceph_osd, o_node);
>> +             struct rb_node *m;
>> +
>> +             m = rb_first(&osd->o_requests);
>> +             while (m) {
>> +                     struct ceph_osd_request *req = rb_entry(m,
>> +                                     struct ceph_osd_request, r_node);
>> +                     m = rb_next(m);
>> +
>> +                     if (req->r_abort_on_full) {
>> +                             victims = true;
>> +                             break;
>> +                     }
>> +             }
>> +             if (victims)
>> +                     break;
>> +     }
>> +
>> +     if (!victims)
>> +             goto out;
>> +
>> +     /*
>> +      * Update the barrier to current epoch since we know we have some
>> +      * calls to be aborted in the tree.
>> +      */
>> +     osdc->epoch_barrier = osdc->osdmap->epoch;
>
> Erm...now that I think about it even more...
>
> Is it possible we can end up with the eb going backward here? Suppose
> we get a MDS cap message with a later epoch barrier, and then a map
> update that is not quite to the barrier yet.
>
> I think we probably want to only set it if it's newer than what's
> there. So this should probably read something like:
>
>         if (osdc->osdmap->epoch > osdc->epoch_barrier)
>                 osdc->epoch_barrier = osdc->osdmap->epoch;
>
> If no one objects, I'll go ahead and make this change in the testing
> branch without a full re-post to the list.

I'd wrap

    if (likely(eb > osdc->epoch_barrier)) {
            dout("updating epoch_barrier from %u to %u\n",
                            osdc->epoch_barrier, eb);
            osdc->epoch_barrier = eb;
            /* Request map if we're not to the barrier yet */
            if (eb > osdc->osdmap->epoch)
                    maybe_request_map(osdc);
    }

from ceph_osdc_update_epoch_barrier() into update_epoch_barrier() and
call it from here.

Thanks,

                Ilya

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v8 4/7] libceph: add an epoch_barrier field to struct ceph_osd_client
  2017-04-18 13:09     ` Ilya Dryomov
@ 2017-04-18 13:24       ` Jeff Layton
  2017-04-18 18:57         ` Ilya Dryomov
  0 siblings, 1 reply; 13+ messages in thread
From: Jeff Layton @ 2017-04-18 13:24 UTC (permalink / raw)
  To: Ilya Dryomov; +Cc: Yan, Zheng, Sage Weil, John Spray, Ceph Development

On Tue, 2017-04-18 at 15:09 +0200, Ilya Dryomov wrote:
> On Tue, Apr 18, 2017 at 2:19 PM, Jeff Layton <jlayton@redhat.com> wrote:
> > On Mon, 2017-04-17 at 12:42 -0400, Jeff Layton wrote:
> > > Cephfs can get cap update requests that contain a new epoch barrier in
> > > them. When that happens we want to pause all OSD traffic until the right
> > > map epoch arrives.
> > > 
> > > Add an epoch_barrier field to ceph_osd_client that is protected by the
> > > osdc->lock rwsem. When the barrier is set, and the current OSD map
> > > epoch is below that, pause the request target when submitting the
> > > request or when revisiting it. Add a way for upper layers (cephfs)
> > > to update the epoch_barrier as well.
> > > 
> > > If we get a new map, compare the new epoch against the barrier before
> > > kicking requests and request another map if the map epoch is still lower
> > > than the one we want.
> > > 
> > > If we get a map with a full pool, or at quota condition, then set the
> > > barrier to the current epoch value.
> > > 
> > > Reviewed-by: "Yan, Zheng” <zyan@redhat.com>
> > > Signed-off-by: Jeff Layton <jlayton@redhat.com>
> > > Reviewed-by: Ilya Dryomov <idryomov@gmail.com>
> > > ---
> > >  include/linux/ceph/osd_client.h |  2 ++
> > >  net/ceph/debugfs.c              |  3 +-
> > >  net/ceph/osd_client.c           | 76 ++++++++++++++++++++++++++++++++++++-----
> > >  3 files changed, 72 insertions(+), 9 deletions(-)
> > > 
> > > diff --git a/include/linux/ceph/osd_client.h b/include/linux/ceph/osd_client.h
> > > index 8cf644197b1a..85650b415e73 100644
> > > --- a/include/linux/ceph/osd_client.h
> > > +++ b/include/linux/ceph/osd_client.h
> > > @@ -267,6 +267,7 @@ struct ceph_osd_client {
> > >       struct rb_root         osds;          /* osds */
> > >       struct list_head       osd_lru;       /* idle osds */
> > >       spinlock_t             osd_lru_lock;
> > > +     u32                    epoch_barrier;
> > >       struct ceph_osd        homeless_osd;
> > >       atomic64_t             last_tid;      /* tid of last request */
> > >       u64                    last_linger_id;
> > > @@ -305,6 +306,7 @@ extern void ceph_osdc_handle_reply(struct ceph_osd_client *osdc,
> > >                                  struct ceph_msg *msg);
> > >  extern void ceph_osdc_handle_map(struct ceph_osd_client *osdc,
> > >                                struct ceph_msg *msg);
> > > +void ceph_osdc_update_epoch_barrier(struct ceph_osd_client *osdc, u32 eb);
> > > 
> > >  extern void osd_req_op_init(struct ceph_osd_request *osd_req,
> > >                           unsigned int which, u16 opcode, u32 flags);
> > > diff --git a/net/ceph/debugfs.c b/net/ceph/debugfs.c
> > > index d7e63a4f5578..71ba13927b3d 100644
> > > --- a/net/ceph/debugfs.c
> > > +++ b/net/ceph/debugfs.c
> > > @@ -62,7 +62,8 @@ static int osdmap_show(struct seq_file *s, void *p)
> > >               return 0;
> > > 
> > >       down_read(&osdc->lock);
> > > -     seq_printf(s, "epoch %d flags 0x%x\n", map->epoch, map->flags);
> > > +     seq_printf(s, "epoch %u barrier %u flags 0x%x\n", map->epoch,
> > > +                     osdc->epoch_barrier, map->flags);
> > > 
> > >       for (n = rb_first(&map->pg_pools); n; n = rb_next(n)) {
> > >               struct ceph_pg_pool_info *pi =
> > > diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
> > > index 55b7585ccefd..beeac4f39aa5 100644
> > > --- a/net/ceph/osd_client.c
> > > +++ b/net/ceph/osd_client.c
> > > @@ -1298,8 +1298,9 @@ static bool target_should_be_paused(struct ceph_osd_client *osdc,
> > >                      __pool_full(pi);
> > > 
> > >       WARN_ON(pi->id != t->base_oloc.pool);
> > > -     return (t->flags & CEPH_OSD_FLAG_READ && pauserd) ||
> > > -            (t->flags & CEPH_OSD_FLAG_WRITE && pausewr);
> > > +     return ((t->flags & CEPH_OSD_FLAG_READ) && pauserd) ||
> > > +            ((t->flags & CEPH_OSD_FLAG_WRITE) && pausewr) ||
> > > +            (osdc->osdmap->epoch < osdc->epoch_barrier);
> > >  }
> > > 
> > >  enum calc_target_result {
> > > @@ -1654,8 +1655,13 @@ static void __submit_request(struct ceph_osd_request *req, bool wrlocked)
> > >               goto promote;
> > >       }
> > > 
> > > -     if ((req->r_flags & CEPH_OSD_FLAG_WRITE) &&
> > > -         ceph_osdmap_flag(osdc, CEPH_OSDMAP_PAUSEWR)) {
> > > +     if (osdc->osdmap->epoch < osdc->epoch_barrier) {
> > > +             dout("req %p epoch %u barrier %u\n", req, osdc->osdmap->epoch,
> > > +                  osdc->epoch_barrier);
> > > +             req->r_t.paused = true;
> > > +             maybe_request_map(osdc);
> > > +     } else if ((req->r_flags & CEPH_OSD_FLAG_WRITE) &&
> > > +                ceph_osdmap_flag(osdc, CEPH_OSDMAP_PAUSEWR)) {
> > >               dout("req %p pausewr\n", req);
> > >               req->r_t.paused = true;
> > >               maybe_request_map(osdc);
> > > @@ -1809,17 +1815,48 @@ static void abort_request(struct ceph_osd_request *req, int err)
> > > 
> > >  /*
> > >   * Drop all pending requests that are stalled waiting on a full condition to
> > > - * clear, and complete them with ENOSPC as the return code.
> > > + * clear, and complete them with ENOSPC as the return code. Set the
> > > + * osdc->epoch_barrier to the latest map epoch that we've seen if any were
> > > + * cancelled.
> > >   */
> > >  static void ceph_osdc_abort_on_full(struct ceph_osd_client *osdc)
> > >  {
> > >       struct rb_node *n;
> > > +     bool victims = false;
> > > 
> > >       dout("enter abort_on_full\n");
> > > 
> > >       if (!ceph_osdmap_flag(osdc, CEPH_OSDMAP_FULL) && !have_pool_full(osdc))
> > >               goto out;
> > > 
> > > +     /* Scan list and see if there is anything to abort */
> > > +     for (n = rb_first(&osdc->osds); n; n = rb_next(n)) {
> > > +             struct ceph_osd *osd = rb_entry(n, struct ceph_osd, o_node);
> > > +             struct rb_node *m;
> > > +
> > > +             m = rb_first(&osd->o_requests);
> > > +             while (m) {
> > > +                     struct ceph_osd_request *req = rb_entry(m,
> > > +                                     struct ceph_osd_request, r_node);
> > > +                     m = rb_next(m);
> > > +
> > > +                     if (req->r_abort_on_full) {
> > > +                             victims = true;
> > > +                             break;
> > > +                     }
> > > +             }
> > > +             if (victims)
> > > +                     break;
> > > +     }
> > > +
> > > +     if (!victims)
> > > +             goto out;
> > > +
> > > +     /*
> > > +      * Update the barrier to current epoch since we know we have some
> > > +      * calls to be aborted in the tree.
> > > +      */
> > > +     osdc->epoch_barrier = osdc->osdmap->epoch;
> > 
> > Erm...now that I think about it even more...
> > 
> > Is it possible we can end up with the eb going backward here? Suppose
> > we get a MDS cap message with a later epoch barrier, and then a map
> > update that is not quite to the barrier yet.
> > 
> > I think we probably want to only set it if it's newer than what's
> > there. So this should probably read something like:
> > 
> >         if (osdc->osdmap->epoch > osdc->epoch_barrier)
> >                 osdc->epoch_barrier = osdc->osdmap->epoch;
> > 
> > If no one objects, I'll go ahead and make this change in the testing
> > branch without a full re-post to the list.
> 
> I'd wrap
> 
>     if (likely(eb > osdc->epoch_barrier)) {
>             dout("updating epoch_barrier from %u to %u\n",
>                             osdc->epoch_barrier, eb);
>             osdc->epoch_barrier = eb;
>             /* Request map if we're not to the barrier yet */
>             if (eb > osdc->osdmap->epoch)
>                     maybe_request_map(osdc);
>     }
> 
> from ceph_osdc_update_epoch_barrier() into update_epoch_barrier() and
> call it from here.
> 

Done. Take a look at the patch in testing branch when you get a chance
and let me know if you see anything wrong there?

Thanks,
-- 
Jeff Layton <jlayton@redhat.com>

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v8 4/7] libceph: add an epoch_barrier field to struct ceph_osd_client
  2017-04-18 13:24       ` Jeff Layton
@ 2017-04-18 18:57         ` Ilya Dryomov
  0 siblings, 0 replies; 13+ messages in thread
From: Ilya Dryomov @ 2017-04-18 18:57 UTC (permalink / raw)
  To: Jeff Layton; +Cc: Yan, Zheng, Sage Weil, John Spray, Ceph Development

On Tue, Apr 18, 2017 at 3:24 PM, Jeff Layton <jlayton@redhat.com> wrote:
> On Tue, 2017-04-18 at 15:09 +0200, Ilya Dryomov wrote:
>> On Tue, Apr 18, 2017 at 2:19 PM, Jeff Layton <jlayton@redhat.com> wrote:
>> > On Mon, 2017-04-17 at 12:42 -0400, Jeff Layton wrote:
>> > > Cephfs can get cap update requests that contain a new epoch barrier in
>> > > them. When that happens we want to pause all OSD traffic until the right
>> > > map epoch arrives.
>> > >
>> > > Add an epoch_barrier field to ceph_osd_client that is protected by the
>> > > osdc->lock rwsem. When the barrier is set, and the current OSD map
>> > > epoch is below that, pause the request target when submitting the
>> > > request or when revisiting it. Add a way for upper layers (cephfs)
>> > > to update the epoch_barrier as well.
>> > >
>> > > If we get a new map, compare the new epoch against the barrier before
>> > > kicking requests and request another map if the map epoch is still lower
>> > > than the one we want.
>> > >
>> > > If we get a map with a full pool, or at quota condition, then set the
>> > > barrier to the current epoch value.
>> > >
>> > > Reviewed-by: "Yan, Zheng” <zyan@redhat.com>
>> > > Signed-off-by: Jeff Layton <jlayton@redhat.com>
>> > > Reviewed-by: Ilya Dryomov <idryomov@gmail.com>
>> > > ---
>> > >  include/linux/ceph/osd_client.h |  2 ++
>> > >  net/ceph/debugfs.c              |  3 +-
>> > >  net/ceph/osd_client.c           | 76 ++++++++++++++++++++++++++++++++++++-----
>> > >  3 files changed, 72 insertions(+), 9 deletions(-)
>> > >
>> > > diff --git a/include/linux/ceph/osd_client.h b/include/linux/ceph/osd_client.h
>> > > index 8cf644197b1a..85650b415e73 100644
>> > > --- a/include/linux/ceph/osd_client.h
>> > > +++ b/include/linux/ceph/osd_client.h
>> > > @@ -267,6 +267,7 @@ struct ceph_osd_client {
>> > >       struct rb_root         osds;          /* osds */
>> > >       struct list_head       osd_lru;       /* idle osds */
>> > >       spinlock_t             osd_lru_lock;
>> > > +     u32                    epoch_barrier;
>> > >       struct ceph_osd        homeless_osd;
>> > >       atomic64_t             last_tid;      /* tid of last request */
>> > >       u64                    last_linger_id;
>> > > @@ -305,6 +306,7 @@ extern void ceph_osdc_handle_reply(struct ceph_osd_client *osdc,
>> > >                                  struct ceph_msg *msg);
>> > >  extern void ceph_osdc_handle_map(struct ceph_osd_client *osdc,
>> > >                                struct ceph_msg *msg);
>> > > +void ceph_osdc_update_epoch_barrier(struct ceph_osd_client *osdc, u32 eb);
>> > >
>> > >  extern void osd_req_op_init(struct ceph_osd_request *osd_req,
>> > >                           unsigned int which, u16 opcode, u32 flags);
>> > > diff --git a/net/ceph/debugfs.c b/net/ceph/debugfs.c
>> > > index d7e63a4f5578..71ba13927b3d 100644
>> > > --- a/net/ceph/debugfs.c
>> > > +++ b/net/ceph/debugfs.c
>> > > @@ -62,7 +62,8 @@ static int osdmap_show(struct seq_file *s, void *p)
>> > >               return 0;
>> > >
>> > >       down_read(&osdc->lock);
>> > > -     seq_printf(s, "epoch %d flags 0x%x\n", map->epoch, map->flags);
>> > > +     seq_printf(s, "epoch %u barrier %u flags 0x%x\n", map->epoch,
>> > > +                     osdc->epoch_barrier, map->flags);
>> > >
>> > >       for (n = rb_first(&map->pg_pools); n; n = rb_next(n)) {
>> > >               struct ceph_pg_pool_info *pi =
>> > > diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
>> > > index 55b7585ccefd..beeac4f39aa5 100644
>> > > --- a/net/ceph/osd_client.c
>> > > +++ b/net/ceph/osd_client.c
>> > > @@ -1298,8 +1298,9 @@ static bool target_should_be_paused(struct ceph_osd_client *osdc,
>> > >                      __pool_full(pi);
>> > >
>> > >       WARN_ON(pi->id != t->base_oloc.pool);
>> > > -     return (t->flags & CEPH_OSD_FLAG_READ && pauserd) ||
>> > > -            (t->flags & CEPH_OSD_FLAG_WRITE && pausewr);
>> > > +     return ((t->flags & CEPH_OSD_FLAG_READ) && pauserd) ||
>> > > +            ((t->flags & CEPH_OSD_FLAG_WRITE) && pausewr) ||
>> > > +            (osdc->osdmap->epoch < osdc->epoch_barrier);
>> > >  }
>> > >
>> > >  enum calc_target_result {
>> > > @@ -1654,8 +1655,13 @@ static void __submit_request(struct ceph_osd_request *req, bool wrlocked)
>> > >               goto promote;
>> > >       }
>> > >
>> > > -     if ((req->r_flags & CEPH_OSD_FLAG_WRITE) &&
>> > > -         ceph_osdmap_flag(osdc, CEPH_OSDMAP_PAUSEWR)) {
>> > > +     if (osdc->osdmap->epoch < osdc->epoch_barrier) {
>> > > +             dout("req %p epoch %u barrier %u\n", req, osdc->osdmap->epoch,
>> > > +                  osdc->epoch_barrier);
>> > > +             req->r_t.paused = true;
>> > > +             maybe_request_map(osdc);
>> > > +     } else if ((req->r_flags & CEPH_OSD_FLAG_WRITE) &&
>> > > +                ceph_osdmap_flag(osdc, CEPH_OSDMAP_PAUSEWR)) {
>> > >               dout("req %p pausewr\n", req);
>> > >               req->r_t.paused = true;
>> > >               maybe_request_map(osdc);
>> > > @@ -1809,17 +1815,48 @@ static void abort_request(struct ceph_osd_request *req, int err)
>> > >
>> > >  /*
>> > >   * Drop all pending requests that are stalled waiting on a full condition to
>> > > - * clear, and complete them with ENOSPC as the return code.
>> > > + * clear, and complete them with ENOSPC as the return code. Set the
>> > > + * osdc->epoch_barrier to the latest map epoch that we've seen if any were
>> > > + * cancelled.
>> > >   */
>> > >  static void ceph_osdc_abort_on_full(struct ceph_osd_client *osdc)
>> > >  {
>> > >       struct rb_node *n;
>> > > +     bool victims = false;
>> > >
>> > >       dout("enter abort_on_full\n");
>> > >
>> > >       if (!ceph_osdmap_flag(osdc, CEPH_OSDMAP_FULL) && !have_pool_full(osdc))
>> > >               goto out;
>> > >
>> > > +     /* Scan list and see if there is anything to abort */
>> > > +     for (n = rb_first(&osdc->osds); n; n = rb_next(n)) {
>> > > +             struct ceph_osd *osd = rb_entry(n, struct ceph_osd, o_node);
>> > > +             struct rb_node *m;
>> > > +
>> > > +             m = rb_first(&osd->o_requests);
>> > > +             while (m) {
>> > > +                     struct ceph_osd_request *req = rb_entry(m,
>> > > +                                     struct ceph_osd_request, r_node);
>> > > +                     m = rb_next(m);
>> > > +
>> > > +                     if (req->r_abort_on_full) {
>> > > +                             victims = true;
>> > > +                             break;
>> > > +                     }
>> > > +             }
>> > > +             if (victims)
>> > > +                     break;
>> > > +     }
>> > > +
>> > > +     if (!victims)
>> > > +             goto out;
>> > > +
>> > > +     /*
>> > > +      * Update the barrier to current epoch since we know we have some
>> > > +      * calls to be aborted in the tree.
>> > > +      */
>> > > +     osdc->epoch_barrier = osdc->osdmap->epoch;
>> >
>> > Erm...now that I think about it even more...
>> >
>> > Is it possible we can end up with the eb going backward here? Suppose
>> > we get a MDS cap message with a later epoch barrier, and then a map
>> > update that is not quite to the barrier yet.
>> >
>> > I think we probably want to only set it if it's newer than what's
>> > there. So this should probably read something like:
>> >
>> >         if (osdc->osdmap->epoch > osdc->epoch_barrier)
>> >                 osdc->epoch_barrier = osdc->osdmap->epoch;
>> >
>> > If no one objects, I'll go ahead and make this change in the testing
>> > branch without a full re-post to the list.
>>
>> I'd wrap
>>
>>     if (likely(eb > osdc->epoch_barrier)) {
>>             dout("updating epoch_barrier from %u to %u\n",
>>                             osdc->epoch_barrier, eb);
>>             osdc->epoch_barrier = eb;
>>             /* Request map if we're not to the barrier yet */
>>             if (eb > osdc->osdmap->epoch)
>>                     maybe_request_map(osdc);
>>     }
>>
>> from ceph_osdc_update_epoch_barrier() into update_epoch_barrier() and
>> call it from here.
>>
>
> Done. Take a look at the patch in testing branch when you get a chance
> and let me know if you see anything wrong there?

Looks fine to me.

Thanks,

                Ilya

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2017-04-18 18:57 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-17 16:42 [PATCH v8 0/7] ceph: implement -ENOSPC handling in cephfs Jeff Layton
2017-04-17 16:42 ` [PATCH v8 1/7] libceph: remove req->r_replay_version Jeff Layton
2017-04-17 16:42 ` [PATCH v8 2/7] libceph: allow requests to return immediately on full conditions if caller wishes Jeff Layton
2017-04-17 16:42 ` [PATCH v8 3/7] libceph: abort already submitted but abortable requests when map or pool goes full Jeff Layton
2017-04-17 16:42 ` [PATCH v8 4/7] libceph: add an epoch_barrier field to struct ceph_osd_client Jeff Layton
2017-04-18 12:19   ` Jeff Layton
2017-04-18 12:38     ` John Spray
2017-04-18 13:09     ` Ilya Dryomov
2017-04-18 13:24       ` Jeff Layton
2017-04-18 18:57         ` Ilya Dryomov
2017-04-17 16:42 ` [PATCH v8 5/7] ceph: handle epoch barriers in cap messages Jeff Layton
2017-04-17 16:42 ` [PATCH v8 6/7] Revert "ceph: SetPageError() for writeback pages if writepages fails" Jeff Layton
2017-04-17 16:42 ` [PATCH v8 7/7] ceph: when seeing write errors on an inode, switch to sync writes Jeff Layton

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.