All of lore.kernel.org
 help / color / mirror / Atom feed
* Can ovl_drop_write() be called earlier in ovl_dentry_open()
@ 2015-06-01 13:52 David Howells
  2015-06-01 14:21 ` [PATCH] overlay: Call ovl_drop_write() " David Howells
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: David Howells @ 2015-06-01 13:52 UTC (permalink / raw)
  To: Miklos Szeredi, viro; +Cc: linux-kernel, linux-fsdevel, linux-unionfs, dhowells

In ovl_dentry_open(), ovl_drop_write() is called after vfs_open() - but is
this actually necessary?  Can't we just drop it post-copyup?  After all,
that's all we wanted the write lock for, right?

David
---
--- a/fs/overlayfs/inode.c
+++ b/fs/overlayfs/inode.c
@@ -356,16 +356,14 @@ static int ovl_dentry_open(struct dentry *dentry, struct inode *inode,
 			err = ovl_copy_up_last(dentry, NULL, true);
 		else
 			err = ovl_copy_up(dentry);
+		ovl_drop_write(dentry);
 		if (err)
-			goto out_drop_write;
+			goto out;
 
 		ovl_path_upper(dentry, &realpath);
 	}
 
 	err = vfs_open(&realpath, d_backing_inode(realpath.dentry), file, cred);
-out_drop_write:
-	if (want_write)
-		ovl_drop_write(dentry);
 out:
 	return err;
 }

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

* [PATCH] overlay: Call ovl_drop_write() earlier in ovl_dentry_open()
  2015-06-01 13:52 Can ovl_drop_write() be called earlier in ovl_dentry_open() David Howells
@ 2015-06-01 14:21 ` David Howells
  2015-06-01 14:22 ` Can ovl_drop_write() be called " Miklos Szeredi
  2015-06-01 15:45 ` David Howells
  2 siblings, 0 replies; 6+ messages in thread
From: David Howells @ 2015-06-01 14:21 UTC (permalink / raw)
  To: viro, miklos; +Cc: linux-fsdevel, dhowells, linux-kernel, linux-unionfs

Call ovl_drop_write() earlier in ovl_dentry_open() before we call vfs_open()
as we've done the copy up for which we needed the freeze-write lock by that
point.

Signed-off-by: David Howells <dhowells@redhat.com>
---

 fs/overlayfs/inode.c |   14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/fs/overlayfs/inode.c b/fs/overlayfs/inode.c
index ce1f349642ab..8a9c32f8f4f9 100644
--- a/fs/overlayfs/inode.c
+++ b/fs/overlayfs/inode.c
@@ -343,31 +343,25 @@ static int ovl_dentry_open(struct dentry *dentry, struct inode *inode,
 	int err;
 	struct path realpath;
 	enum ovl_path_type type;
-	bool want_write = false;
 
 	type = ovl_path_real(dentry, &realpath);
 	if (ovl_open_need_copy_up(file->f_flags, type, realpath.dentry)) {
-		want_write = true;
 		err = ovl_want_write(dentry);
 		if (err)
-			goto out;
+			return err;
 
 		if (file->f_flags & O_TRUNC)
 			err = ovl_copy_up_last(dentry, NULL, true);
 		else
 			err = ovl_copy_up(dentry);
+		ovl_drop_write(dentry);
 		if (err)
-			goto out_drop_write;
+			return err;
 
 		ovl_path_upper(dentry, &realpath);
 	}
 
-	err = vfs_open(&realpath, d_backing_inode(realpath.dentry), file, cred);
-out_drop_write:
-	if (want_write)
-		ovl_drop_write(dentry);
-out:
-	return err;
+	return vfs_open(&realpath, d_backing_inode(realpath.dentry), file, cred);
 }
 
 static const struct inode_operations ovl_file_inode_operations = {

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

* Re: Can ovl_drop_write() be called earlier in ovl_dentry_open()
  2015-06-01 13:52 Can ovl_drop_write() be called earlier in ovl_dentry_open() David Howells
  2015-06-01 14:21 ` [PATCH] overlay: Call ovl_drop_write() " David Howells
@ 2015-06-01 14:22 ` Miklos Szeredi
  2015-06-01 15:45 ` David Howells
  2 siblings, 0 replies; 6+ messages in thread
From: Miklos Szeredi @ 2015-06-01 14:22 UTC (permalink / raw)
  To: David Howells; +Cc: Al Viro, Kernel Mailing List, Linux-Fsdevel, linux-unionfs

On Mon, Jun 1, 2015 at 3:52 PM, David Howells <dhowells@redhat.com> wrote:
> In ovl_dentry_open(), ovl_drop_write() is called after vfs_open() - but is
> this actually necessary?  Can't we just drop it post-copyup?  After all,
> that's all we wanted the write lock for, right?

Hmm,  that could result in a race where remount r/o of upper fs comes
in between copy-up and vfs_open() so copy-up succeeds but the actual
open fails.  It's harmless, though, and not  very likely.  So I guess
your patch is OK.

Thanks,
Miklos




>
> David
> ---
> --- a/fs/overlayfs/inode.c
> +++ b/fs/overlayfs/inode.c
> @@ -356,16 +356,14 @@ static int ovl_dentry_open(struct dentry *dentry, struct inode *inode,
>                         err = ovl_copy_up_last(dentry, NULL, true);
>                 else
>                         err = ovl_copy_up(dentry);
> +               ovl_drop_write(dentry);
>                 if (err)
> -                       goto out_drop_write;
> +                       goto out;
>
>                 ovl_path_upper(dentry, &realpath);
>         }
>
>         err = vfs_open(&realpath, d_backing_inode(realpath.dentry), file, cred);
> -out_drop_write:
> -       if (want_write)
> -               ovl_drop_write(dentry);
>  out:
>         return err;
>  }

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

* Re: Can ovl_drop_write() be called earlier in ovl_dentry_open()
  2015-06-01 13:52 Can ovl_drop_write() be called earlier in ovl_dentry_open() David Howells
  2015-06-01 14:21 ` [PATCH] overlay: Call ovl_drop_write() " David Howells
  2015-06-01 14:22 ` Can ovl_drop_write() be called " Miklos Szeredi
@ 2015-06-01 15:45 ` David Howells
  2015-06-01 15:51   ` Miklos Szeredi
  2015-06-01 15:53   ` David Howells
  2 siblings, 2 replies; 6+ messages in thread
From: David Howells @ 2015-06-01 15:45 UTC (permalink / raw)
  To: Miklos Szeredi
  Cc: dhowells, Al Viro, Kernel Mailing List, Linux-Fsdevel, linux-unionfs

Miklos Szeredi <miklos@szeredi.hu> wrote:

> > In ovl_dentry_open(), ovl_drop_write() is called after vfs_open() - but is
> > this actually necessary?  Can't we just drop it post-copyup?  After all,
> > that's all we wanted the write lock for, right?
> 
> Hmm,  that could result in a race where remount r/o of upper fs comes
> in between copy-up and vfs_open() so copy-up succeeds but the actual
> open fails.  It's harmless, though, and not  very likely.  So I guess
> your patch is OK.

That race is there anyway if there's no copy up, right?

David

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

* Re: Can ovl_drop_write() be called earlier in ovl_dentry_open()
  2015-06-01 15:45 ` David Howells
@ 2015-06-01 15:51   ` Miklos Szeredi
  2015-06-01 15:53   ` David Howells
  1 sibling, 0 replies; 6+ messages in thread
From: Miklos Szeredi @ 2015-06-01 15:51 UTC (permalink / raw)
  To: David Howells; +Cc: Al Viro, Kernel Mailing List, Linux-Fsdevel, linux-unionfs

On Mon, Jun 1, 2015 at 5:45 PM, David Howells <dhowells@redhat.com> wrote:
> Miklos Szeredi <miklos@szeredi.hu> wrote:
>
>> > In ovl_dentry_open(), ovl_drop_write() is called after vfs_open() - but is
>> > this actually necessary?  Can't we just drop it post-copyup?  After all,
>> > that's all we wanted the write lock for, right?
>>
>> Hmm,  that could result in a race where remount r/o of upper fs comes
>> in between copy-up and vfs_open() so copy-up succeeds but the actual
>> open fails.  It's harmless, though, and not  very likely.  So I guess
>> your patch is OK.
>
> That race is there anyway if there's no copy up, right?

No.  The race I'm talking about is that with your patch it's possible
that the file will be copied up, but open will return -EROFS.

Without your patch, that is not possible since holding write counter
for the mnt over both the copy-up and the open ensures that the
filesystem cannot become read-only in the middle.

So your patch changes behavior, but the new behavior is acceptable,
because there's no major change in semantics (it should only be
detectable by the increased disk usage in the rare case of the failed
open).

Thanks,
Miklos

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

* Re: Can ovl_drop_write() be called earlier in ovl_dentry_open()
  2015-06-01 15:45 ` David Howells
  2015-06-01 15:51   ` Miklos Szeredi
@ 2015-06-01 15:53   ` David Howells
  1 sibling, 0 replies; 6+ messages in thread
From: David Howells @ 2015-06-01 15:53 UTC (permalink / raw)
  To: Miklos Szeredi
  Cc: dhowells, Al Viro, Kernel Mailing List, Linux-Fsdevel, linux-unionfs

Miklos Szeredi <miklos@szeredi.hu> wrote:

> >> Hmm,  that could result in a race where remount r/o of upper fs comes
> >> in between copy-up and vfs_open() so copy-up succeeds but the actual
> >> open fails.  It's harmless, though, and not  very likely.  So I guess
> >> your patch is OK.
> >
> > That race is there anyway if there's no copy up, right?
> 
> No.  The race I'm talking about is that with your patch it's possible
> that the file will be copied up, but open will return -EROFS.

Ah, I see what you're getting at.

> Without your patch, that is not possible since holding write counter
> for the mnt over both the copy-up and the open ensures that the
> filesystem cannot become read-only in the middle.
> 
> So your patch changes behavior, but the new behavior is acceptable,
> because there's no major change in semantics (it should only be
> detectable by the increased disk usage in the rare case of the failed
> open).

Okay.

David

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

end of thread, other threads:[~2015-06-01 15:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-01 13:52 Can ovl_drop_write() be called earlier in ovl_dentry_open() David Howells
2015-06-01 14:21 ` [PATCH] overlay: Call ovl_drop_write() " David Howells
2015-06-01 14:22 ` Can ovl_drop_write() be called " Miklos Szeredi
2015-06-01 15:45 ` David Howells
2015-06-01 15:51   ` Miklos Szeredi
2015-06-01 15:53   ` David Howells

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.