Skip to contentSkip to conversation

ceph: misc fixes

PATCH In review Yan, Zheng 3 participants 11 messages Feb 22, 2013 – Feb 26, 2013 Ceph client

lore
Share & tools
lore

Yan, Zheng

author
#0 lore raw

cover ceph: misc fixes

These patches are also in:
git://github.com/ukernel/linux.git wip-ceph

author
#1 lore raw

PATCH 1/3 ceph: fix LSSNAP regression

From: "Yan, Zheng" <[email protected]>

commit 6e8575faa8 makes parse_reply_info_extra() return -EIO for LSSNAP

---
 fs/ceph/mds_client.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
fs/ceph/mds_client.c +2 -1
index d958420..608ffcf 100644
@@ -265,7 +265,8 @@ static int parse_reply_info_extra(void **p, void *end,
 {
 	if (info->head->op == CEPH_MDS_OP_GETFILELOCK)
 		return parse_reply_info_filelock(p, end, info, features);
-	else if (info->head->op == CEPH_MDS_OP_READDIR)
+	else if (info->head->op == CEPH_MDS_OP_READDIR ||
+		 info->head->op == CEPH_MDS_OP_LSSNAP)
 		return parse_reply_info_dir(p, end, info, features);
 	else if (info->head->op == CEPH_MDS_OP_CREATE)
 		return parse_reply_info_create(p, end, info, features);
Signature · 1 line
1.7.11.7
author
#2 lore raw

PATCH 2/3 ceph: queue cap release when trimming cap

In reply to Yan, Zheng

From: "Yan, Zheng" <[email protected]>

So the client will later send cap release message to MDS

---
 fs/ceph/caps.c       | 6 +++---
 fs/ceph/mds_client.c | 2 ++
 fs/ceph/super.h      | 2 ++
 3 files changed, 7 insertions(+), 3 deletions(-)
fs/ceph/caps.c +3 -3
index 1e1e020..5d5c32b 100644
@@ -997,9 +997,9 @@ static int send_cap_msg(struct ceph_mds_session *session,
 	return 0;
 }
 
-static void __queue_cap_release(struct ceph_mds_session *session,
-				u64 ino, u64 cap_id, u32 migrate_seq,
-				u32 issue_seq)
+void __queue_cap_release(struct ceph_mds_session *session,
+			 u64 ino, u64 cap_id, u32 migrate_seq,
+			 u32 issue_seq)
 {
 	struct ceph_msg *msg;
 	struct ceph_mds_cap_release *head;
fs/ceph/mds_client.c +2 -0
index 608ffcf..ccc68b0 100644
@@ -1197,6 +1197,8 @@ static int trim_caps_cb(struct inode *inode, struct ceph_cap *cap, void *arg)
 	session->s_trim_caps--;
 	if (oissued) {
 		/* we aren't the only cap.. just remove us */
+		__queue_cap_release(session, ceph_ino(inode), cap->cap_id,
+				    cap->mseq, cap->issue_seq);
 		__ceph_remove_cap(cap);
 	} else {
 		/* try to drop referring dentries */
fs/ceph/super.h +2 -0
index 66ebe72..e1eb50a 100644
@@ -755,6 +755,8 @@ static inline void ceph_remove_cap(struct ceph_cap *cap)
 extern void ceph_put_cap(struct ceph_mds_client *mdsc,
 			 struct ceph_cap *cap);
 
+extern void __queue_cap_release(struct ceph_mds_session *session, u64 ino,
+				u64 cap_id, u32 migrate_seq, u32 issue_seq);
 extern void ceph_queue_caps_release(struct inode *inode);
 extern int ceph_write_inode(struct inode *inode, struct writeback_control *wbc);
 extern int ceph_fsync(struct file *file, loff_t start, loff_t end,
Signature · 1 line
1.7.11.7
author
#3 lore raw

PATCH 3/3 ceph: fix vmtruncate deadlock

In reply to Yan, Zheng

From: "Yan, Zheng" <[email protected]>

If there is pending truncation, ceph_get_caps() waits for a work thread to apply it. To apply pending truncation, the work thread needs acquire i_mutex. But in the buffered write case, ceph_get_caps() is called while i_mutex is locked. So the writer and the work thread wait for each other

The fix is make ceph_get_caps() not wait, apply pending truncation in ceph_aio_write() instead.

---
 fs/ceph/caps.c |  6 ------
 fs/ceph/file.c | 15 ++++++++++-----
 2 files changed, 10 insertions(+), 11 deletions(-)
fs/ceph/caps.c +0 -6
index 5d5c32b..b9d8417 100644
@@ -2067,12 +2067,6 @@ static int try_get_cap_refs(struct ceph_inode_info *ci, int need, int want,
 	}
 	have = __ceph_caps_issued(ci, &implemented);
 
-	/*
-	 * disallow writes while a truncate is pending
-	 */
-	if (ci->i_truncate_pending)
-		have &= ~CEPH_CAP_FILE_WR;
-
 	if ((have & need) == need) {
 		/*
 		 * Look at (implemented & ~have & not) so that we keep waiting
fs/ceph/file.c +10 -5
index a1e5b81..bf7849a 100644
@@ -653,7 +653,6 @@ static ssize_t ceph_aio_read(struct kiocb *iocb, const struct iovec *iov,
 	dout("aio_read %p %llx.%llx %llu~%u trying to get caps on %p\n",
 	     inode, ceph_vinop(inode), pos, (unsigned)len, inode);
 again:
-	__ceph_do_pending_vmtruncate(inode);
 	if (fi->fmode & CEPH_FILE_MODE_LAZY)
 		want = CEPH_CAP_FILE_CACHE | CEPH_CAP_FILE_LAZYIO;
 	else
@@ -724,11 +723,13 @@ static ssize_t ceph_aio_write(struct kiocb *iocb, const struct iovec *iov,
 	if (ceph_snap(inode) != CEPH_NOSNAP)
 		return -EROFS;
 
+	sb_start_write(inode->i_sb);
 retry_snap:
 	written = 0;
-	if (ceph_osdmap_flag(osdc->osdmap, CEPH_OSDMAP_FULL))
-		return -ENOSPC;
-	__ceph_do_pending_vmtruncate(inode);
+	if (ceph_osdmap_flag(osdc->osdmap, CEPH_OSDMAP_FULL)) {
+		ret = -ENOSPC;
+		goto out;
+	}
 
 	/*
 	 * try to do a buffered write.  if we don't have sufficient
@@ -738,7 +739,10 @@ retry_snap:
 	if (!(iocb->ki_filp->f_flags & O_DIRECT) &&
 	    !(inode->i_sb->s_flags & MS_SYNCHRONOUS) &&
 	    !(fi->flags & CEPH_F_SYNC)) {
-		ret = generic_file_aio_write(iocb, iov, nr_segs, pos);
+		mutex_lock(&inode->i_mutex);
+		__ceph_do_pending_vmtruncate(inode);
+		ret = __generic_file_aio_write(iocb, iov, nr_segs, &iocb->ki_pos);
+		mutex_unlock(&inode->i_mutex);
 		if (ret >= 0)
 			written = ret;
 
@@ -783,6 +787,7 @@ out:
 		     inode, ceph_vinop(inode), pos, (unsigned)iov->iov_len);
 		goto retry_snap;
 	}
+	sb_end_write(inode->i_sb);
 
 	return ret;
 }
Signature · 1 line
1.7.11.7
#4 lore raw

Re: [PATCH 3/3] ceph: fix vmtruncate deadlock

I haven't spent that much time in the kernel client, but this patch isn't working out for me. In particular, I'm pretty sure we need to preserve this:

Quoted 7 lines
fs/ceph/caps.c +0 -0
index 5d5c32b..b9d8417 100644
@@ -2067,12 +2067,6 @@ static int try_get_cap_refs(struct ceph_inode_info *ci, int need, int want,
        }
        have = __ceph_caps_issued(ci, &implemented);

fs/ceph/caps.c static int try_get_cap_refs(struct ceph_inode_info *ci, int need, int want, · line 2072

Quoted 10 lines
fs/ceph/caps.c +0 -6
 
-       /*
-        * disallow writes while a truncate is pending
-        */
-       if (ci->i_truncate_pending)
-               have &= ~CEPH_CAP_FILE_WR;
-
        if ((have & need) == need) {
                /*
                 * Look at (implemented & ~have & not) so that we keep waiting

Because if there's a pending truncate, we really can't write. You do handle it in the particular case of doing buffered file writes, but these caps are a marker of permission, and the client shouldn't have write permission to a file until it's up to date on the truncates. Or am I misunderstanding something?

fs/ceph/file.c static ssize_t ceph_aio_read(struct kiocb *iocb, const struct iovec *iov, · line 656

Quoted 9 lines
fs/ceph/file.c +0 -1
index a1e5b81..bf7849a 100644
@@ -653,7 +653,6 @@ static ssize_t ceph_aio_read(struct kiocb *iocb, const struct iovec *iov,
        dout("aio_read %p %llx.%llx %llu~%u trying to get caps on %p\n",
             inode, ceph_vinop(inode), pos, (unsigned)len, inode);
 again:
-       __ceph_do_pending_vmtruncate(inode);

There doesn't seem to be any kind of replacement for this? We need to do any pending truncates before reading or we might get stale data back.

The first two in the series look good to me, but I'll wait and pull them in as a unit with this one once we're done discussing. :) -Greg

author
#5 lore raw

Re: [PATCH 3/3] ceph: fix vmtruncate deadlock

Quoted 12 lines · Gregory Farnum

I haven't spent that much time in the kernel client, but this patch isn't working out for me. In particular, I'm pretty sure we need to preserve this:

Quoted 8 lines
fs/ceph/caps.c +0 -0
index 5d5c32b..b9d8417 100644
@@ -2067,12 +2067,6 @@ static int try_get_cap_refs(struct ceph_inode_info *ci, int need, int want,
        }
        have = __ceph_caps_issued(ci, &implemented);
 
Quoted 15 lines

fs/ceph/caps.c static int try_get_cap_refs(struct ceph_inode_info *ci, int need, int want, · line 2072

Quoted 9 lines
fs/ceph/caps.c +0 -6
-       /*
-        * disallow writes while a truncate is pending
-        */
-       if (ci->i_truncate_pending)
-               have &= ~CEPH_CAP_FILE_WR;
-
        if ((have & need) == need) {
                /*
                 * Look at (implemented & ~have & not) so that we keep waiting

Because if there's a pending truncate, we really can't write. You do handle it in the particular case of doing buffered file writes, but these caps are a marker of permission, and the client shouldn't have write permission to a file until it's up to date on the truncates. Or am I misunderstanding something?

pending vmtruncate is only relevant to buffered write case. If client doesn't have 'b' cap, the page cache is empty, and __ceph_do_pending_vmtruncate is no-op. For buffered write, this patch only affects situation that clients receives truncate request from MDS in the middle of write. I think it's better to do vmtruncate after write finishes.

Quoted 15 lines

fs/ceph/file.c static ssize_t ceph_aio_read(struct kiocb *iocb, const struct iovec *iov, · line 656

Quoted 11 lines
fs/ceph/file.c +0 -1
index a1e5b81..bf7849a 100644
@@ -653,7 +653,6 @@ static ssize_t ceph_aio_read(struct kiocb *iocb, const struct iovec *iov,
        dout("aio_read %p %llx.%llx %llu~%u trying to get caps on %p\n",
             inode, ceph_vinop(inode), pos, (unsigned)len, inode);
 again:
-       __ceph_do_pending_vmtruncate(inode);

There doesn't seem to be any kind of replacement for this? We need to do any pending truncates before reading or we might get stale data back.

generic_file_aio_read checks i_size when coping data to user buffer, so the user program can't get stale data. This __ceph_do_pending_vmtruncate is not protected by i_mutex, it's a potential bug, that's the reason I remove it.

Regards
Yan, Zheng

Quoted 5 lines

The first two in the series look good to me, but I'll wait and pull them in as a unit with this one once we're done discussing. :) -Greg

#6 lore raw

Re: [PATCH 3/3] ceph: fix vmtruncate deadlock

Quoted 29 lines · Zheng
Quoted 12 lines · Gregory Farnum

I haven't spent that much time in the kernel client, but this patch isn't working out for me. In particular, I'm pretty sure we need to preserve this:

Quoted 8 lines
fs/ceph/caps.c +0 -0
index 5d5c32b..b9d8417 100644
@@ -2067,12 +2067,6 @@ static int try_get_cap_refs(struct ceph_inode_info *ci, int need, int want,
        }
        have = __ceph_caps_issued(ci, &implemented);
 
Quoted 15 lines

fs/ceph/caps.c static int try_get_cap_refs(struct ceph_inode_info *ci, int need, int want, · line 2072

Quoted 9 lines
fs/ceph/caps.c +0 -6
-       /*
-        * disallow writes while a truncate is pending
-        */
-       if (ci->i_truncate_pending)
-               have &= ~CEPH_CAP_FILE_WR;
-
        if ((have & need) == need) {
                /*
                 * Look at (implemented & ~have & not) so that we keep waiting

Because if there's a pending truncate, we really can't write. You do handle it in the particular case of doing buffered file writes, but these caps are a marker of permission, and the client shouldn't have write permission to a file until it's up to date on the truncates. Or am I misunderstanding something?

Quoted 4 lines

pending vmtruncate is only relevant to buffered write case. If client doesn't have 'b' cap, the page cache is empty, and __ceph_do_pending_vmtruncate is no-op. For buffered write, this patch only affects situation that clients receives truncate request from MDS in the middle of write.

It looks to me like truncates can get queued for later, so that's not the case? And how could the client receive a truncate while in the middle of writing? Either it's got the write caps (in which case nobody else can truncate), or it shouldn't be writing...I suppose if somebody enables lazyIO that would do it, but again in that case I imagine we'd rather do the truncate before writing:

Quoted 1 line

I think it's better to do vmtruncate after write finishes.

What if you're writing past the truncate point? Then your written data would be truncated off even though it should have been a file extension.

Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
fs/ceph/file.c +0 -0
index a1e5b81..bf7849a 100644
@@ -653,7 +653,6 @@ static ssize_t ceph_aio_read(struct kiocb *iocb, const struct iovec *iov,
Quoted 8 lines

fs/ceph/file.c static ssize_t ceph_aio_read(struct kiocb *iocb, const struct iovec *iov, · line 656

Quoted 4 lines
fs/ceph/file.c +0 -1
        dout("aio_read %p %llx.%llx %llu~%u trying to get caps on %p\n",
             inode, ceph_vinop(inode), pos, (unsigned)len, inode);
 again:
-       __ceph_do_pending_vmtruncate(inode);

There doesn't seem to be any kind of replacement for this? We need to do any pending truncates before reading or we might get stale data back.

Quoted 3 lines

generic_file_aio_read checks i_size when coping data to user buffer, so the user program can't get stale data. This __ceph_do_pending_vmtruncate is not protected by i_mutex, it's a potential bug, that's the reason I remove it.

Oh, you're right about the locking (I think, anyway?). However, i_size doesn't protect us — we might for instance have truncated to zero and then back up to the original file size. :( But that doesn't look like it's handled correctly anyway (racy) — am I misreading that badly or is the infrastructure in fact broken in that case?

As I said, I don't spend much time in the kernel client, but I looked around a bit more and this is what I came up with. Education, if nothing else. ;)
-Greg
--
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

author
#7 lore raw

Re: [PATCH 3/3] ceph: fix vmtruncate deadlock

Quoted 34 lines · Gregory Farnum
Quoted 29 lines · Zheng
Quoted 12 lines · Gregory Farnum

I haven't spent that much time in the kernel client, but this patch isn't working out for me. In particular, I'm pretty sure we need to preserve this:

Quoted 8 lines
fs/ceph/caps.c +0 -0
index 5d5c32b..b9d8417 100644
@@ -2067,12 +2067,6 @@ static int try_get_cap_refs(struct ceph_inode_info *ci, int need, int want,
        }
        have = __ceph_caps_issued(ci, &implemented);
 
Quoted 15 lines

fs/ceph/caps.c static int try_get_cap_refs(struct ceph_inode_info *ci, int need, int want, · line 2072

Quoted 9 lines
fs/ceph/caps.c +0 -6
-       /*
-        * disallow writes while a truncate is pending
-        */
-       if (ci->i_truncate_pending)
-               have &= ~CEPH_CAP_FILE_WR;
-
        if ((have & need) == need) {
                /*
                 * Look at (implemented & ~have & not) so that we keep waiting

Because if there's a pending truncate, we really can't write. You do handle it in the particular case of doing buffered file writes, but these caps are a marker of permission, and the client shouldn't have write permission to a file until it's up to date on the truncates. Or am I misunderstanding something?

Quoted 4 lines

pending vmtruncate is only relevant to buffered write case. If client doesn't have 'b' cap, the page cache is empty, and __ceph_do_pending_vmtruncate is no-op. For buffered write, this patch only affects situation that clients receives truncate request from MDS in the middle of write.

Quoted 6 lines

It looks to me like truncates can get queued for later, so that's not the case? And how could the client receive a truncate while in the middle of writing? Either it's got the write caps (in which case nobody else can truncate), or it shouldn't be writing...I suppose if somebody enables lazyIO that would do it, but again in that case I imagine we'd rather do the truncate before writing:

Commit 22cddde104 make buffered write get/put caps for individual page. So the MDS can revoke the write caps in the middle of write.

Quoted 6 lines
Quoted 2 lines

I think it's better to do vmtruncate after write finishes.

What if you're writing past the truncate point? Then your written data would be truncated off even though it should have been a file extension.

I was wrong, I thought the order of write and truncate is not important. Now I'm worry about the correctness of commit 22cddde104, we probably should revert that commit.

Quoted 19 lines
Quoted 15 lines
Quoted 14 lines

fs/ceph/file.c static ssize_t ceph_aio_read(struct kiocb *iocb, const struct iovec *iov, · line 656

Quoted 10 lines
fs/ceph/file.c +0 -1
index a1e5b81..bf7849a 100644
@@ -653,7 +653,6 @@ static ssize_t ceph_aio_read(struct kiocb *iocb, const struct iovec *iov,
        dout("aio_read %p %llx.%llx %llu~%u trying to get caps on %p\n",
             inode, ceph_vinop(inode), pos, (unsigned)len, inode);
 again:
-       __ceph_do_pending_vmtruncate(inode);

There doesn't seem to be any kind of replacement for this? We need to do any pending truncates before reading or we might get stale data back.

Quoted 3 lines

generic_file_aio_read checks i_size when coping data to user buffer, so the user program can't get stale data. This __ceph_do_pending_vmtruncate is not protected by i_mutex, it's a potential bug, that's the reason I remove it.

Quoted 5 lines

Oh, you're right about the locking (I think, anyway?). However, i_size doesn't protect us — we might for instance have truncated to zero and then back up to the original file size. :( But that doesn't look like it's handled correctly anyway (racy) — am I misreading that badly or is the infrastructure in fact broken in that case?

You are right. probably we can fix the race by disallowing both read and write when there is pending truncate.

Thank you
Yan, Zheng

Quoted 6 lines

As I said, I don't spend much time in the kernel client, but I looked around a bit more and this is what I came up with. Education, if nothing else. ;)
-Greg

--
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

#8 lore raw

Re: [PATCH 3/3] ceph: fix vmtruncate deadlock

Quoted 11 lines · Zheng
Quoted 6 lines

It looks to me like truncates can get queued for later, so that's not the case? And how could the client receive a truncate while in the middle of writing? Either it's got the write caps (in which case nobody else can truncate), or it shouldn't be writing...I suppose if somebody enables lazyIO that would do it, but again in that case I imagine we'd rather do the truncate before writing:

Commit 22cddde104 make buffered write get/put caps for individual page. So the MDS can revoke the write caps in the middle of write.

Quoted 1 line
Quoted 8 lines
Quoted 5 lines
Quoted 1 line

I think it's better to do vmtruncate after write finishes.

What if you're writing past the truncate point? Then your written data would be truncated off even though it should have been a file extension.

I was wrong, I thought the order of write and truncate is not important. Now I'm worry about the correctness of commit 22cddde104, we probably should revert that commit.

I'm sorry I haven't had time to dig into this thread. Do you think we should revert that commit for this merge window?

My gut feeling is that the whole locking scheme here needs to be reworked. I suspect where we'll end up is something more like XFS, where there is an explicit truncate (or other) mutex that is separate from i_mutex. The fact that we were relying on i_mutex serialization from the VFS was fragile and (as we can see) ultimately a flawed approach. And the locking and races between writes, mmap, and truncation in the page cache code are fragile and annoying. The only good thing going for us is that fsx is pretty good at stress testing the code. :)

Quoted 8 lines
Quoted 5 lines

Oh, you're right about the locking (I think, anyway?). However, i_size doesn't protect us ? we might for instance have truncated to zero and then back up to the original file size. :( But that doesn't look like it's handled correctly anyway (racy) ? am I misreading that badly or is the infrastructure in fact broken in that case?

You are right. probably we can fix the race by disallowing both read and write when there is pending truncate.

FWIW, I think the high-level strategy before should still be basically
sound: we can queue a truncation without blocking, and any write path will apply a pending truncation under the appropriate lock. But I think it's going to mean carefully documenting the locking requirements for the various paths and working out a new locking structure.

Yan, is this something you are able to put some time into? I would like to work on it, but it's going to be hard for me to find the time in the next several weeks to get to it.

sage

author
#9 lore raw

Re: [PATCH 3/3] ceph: fix vmtruncate deadlock

Quoted 17 lines · Sage Weil
Quoted 16 lines · Zheng
Quoted 6 lines

It looks to me like truncates can get queued for later, so that's not the case? And how could the client receive a truncate while in the middle of writing? Either it's got the write caps (in which case nobody else can truncate), or it shouldn't be writing...I suppose if somebody enables lazyIO that would do it, but again in that case I imagine we'd rather do the truncate before writing:

Commit 22cddde104 make buffered write get/put caps for individual page. So the MDS can revoke the write caps in the middle of write.

Quoted 6 lines
Quoted 2 lines

I think it's better to do vmtruncate after write finishes.

What if you're writing past the truncate point? Then your written data would be truncated off even though it should have been a file extension.

Quoted 6 lines
Quoted 3 lines

I was wrong, I thought the order of write and truncate is not important. Now I'm worry about the correctness of commit 22cddde104, we probably should revert that commit.

I'm sorry I haven't had time to dig into this thread. Do you think we should revert that commit for this merge window?

No, that commit fixes a i_size update bug, it is more important than the deadlock. But I think the eventual fix is revert that commit and also remove the optimization that drops Fw caps early (to avoid slow cap revocation caused by balance_dirty_pages)

Quoted 9 lines

My gut feeling is that the whole locking scheme here needs to be reworked. I suspect where we'll end up is something more like XFS, where there is an explicit truncate (or other) mutex that is separate from i_mutex. The fact that we were relying on i_mutex serialization from the VFS was fragile and (as we can see) ultimately a flawed approach. And the locking and races between writes, mmap, and truncation in the page cache code are fragile and annoying. The only good thing going for us is that fsx is pretty good at stress testing the code. :)

If we want to keep write operation atomic, write and vmtruncate need to be protected by a mutex. I don't think introducing a new mutex makes thing simple.

Quoted 16 lines
Quoted 9 lines
Quoted 6 lines

Oh, you're right about the locking (I think, anyway?). However, i_size doesn't protect us ? we might for instance have truncated to zero and then back up to the original file size. :( But that doesn't look like it's handled correctly anyway (racy) ? am I misreading that badly or is the infrastructure in fact broken in that case?

You are right. probably we can fix the race by disallowing both read and write when there is pending truncate.

FWIW, I think the high-level strategy before should still be basically
sound: we can queue a truncation without blocking, and any write path will apply a pending truncation under the appropriate lock. But I think it's going to mean carefully documenting the locking requirements for the various paths and working out a new locking structure.

Quoted 3 lines

Yan, is this something you are able to put some time into? I would like to work on it, but it's going to be hard for me to find the time in the next several weeks to get to it.

OK, I will work on it.

Regards
Yan, Zheng

--
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

#10 lore raw

Re: [PATCH 3/3] ceph: fix vmtruncate deadlock

In reply to Gregory Farnum
Quoted 65 lines · Gregory Farnum
Quoted 29 lines · Zheng
Quoted 12 lines · Gregory Farnum

I haven't spent that much time in the kernel client, but this patch isn't working out for me. In particular, I'm pretty sure we need to preserve this:

Quoted 8 lines
fs/ceph/caps.c +0 -0
index 5d5c32b..b9d8417 100644
@@ -2067,12 +2067,6 @@ static int try_get_cap_refs(struct ceph_inode_info *ci, int need, int want,
        }
        have = __ceph_caps_issued(ci, &implemented);
 
Quoted 15 lines

fs/ceph/caps.c static int try_get_cap_refs(struct ceph_inode_info *ci, int need, int want, · line 2072

Quoted 9 lines
fs/ceph/caps.c +0 -6
-       /*
-        * disallow writes while a truncate is pending
-        */
-       if (ci->i_truncate_pending)
-               have &= ~CEPH_CAP_FILE_WR;
-
        if ((have & need) == need) {
                /*
                 * Look at (implemented & ~have & not) so that we keep waiting

Because if there's a pending truncate, we really can't write. You do handle it in the particular case of doing buffered file writes, but these caps are a marker of permission, and the client shouldn't have write permission to a file until it's up to date on the truncates. Or am I misunderstanding something?

Quoted 4 lines

pending vmtruncate is only relevant to buffered write case. If client doesn't have 'b' cap, the page cache is empty, and __ceph_do_pending_vmtruncate is no-op. For buffered write, this patch only affects situation that clients receives truncate request from MDS in the middle of write.

It looks to me like truncates can get queued for later, so that's not the case? And how could the client receive a truncate while in the middle of writing? Either it's got the write caps (in which case nobody else can truncate), or it shouldn't be writing...I suppose if somebody enables lazyIO that would do it, but again in that case I imagine we'd rather do the truncate before writing:

Quoted 1 line

I think it's better to do vmtruncate after write finishes.

What if you're writing past the truncate point? Then your written data would be truncated off even though it should have been a file extension.

Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
fs/ceph/file.c +0 -0
index a1e5b81..bf7849a 100644
@@ -653,7 +653,6 @@ static ssize_t ceph_aio_read(struct kiocb *iocb, const struct iovec *iov,
Quoted 8 lines

fs/ceph/file.c static ssize_t ceph_aio_read(struct kiocb *iocb, const struct iovec *iov, · line 656

Quoted 4 lines
fs/ceph/file.c +0 -1
        dout("aio_read %p %llx.%llx %llu~%u trying to get caps on %p\n",
             inode, ceph_vinop(inode), pos, (unsigned)len, inode);
 again:
-       __ceph_do_pending_vmtruncate(inode);

There doesn't seem to be any kind of replacement for this? We need to do any pending truncates before reading or we might get stale data back.

Quoted 3 lines

generic_file_aio_read checks i_size when coping data to user buffer, so the user program can't get stale data. This __ceph_do_pending_vmtruncate is not protected by i_mutex, it's a potential bug, that's the reason I remove it.

Quoted 5 lines

Oh, you're right about the locking (I think, anyway?). However, i_size doesn't protect us — we might for instance have truncated to zero and then back up to the original file size. :( But that doesn't look like it's handled correctly anyway (racy) — am I misreading that badly or is the infrastructure in fact broken in that case?

Sage pointed out in standup today that we only send a truncate message for truncate downs, and he thinks that the more complicated cases (truncate to zero, write out 2KB, truncate to 1KB) are okay thanks to the capabilities bits. I haven't thought it through but that seems plausible to me.
-Greg
--
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