Skip to contentSkip to conversation

add support for nfs_umount

PATCH In review Peter Lieven 4 participants 10 messages Sep 10, 2019 – Sep 13, 2019 Block layer

lore
Share & tools
lore
#0 lore raw

v2 cover add support for nfs_umount

add support for NFSv3 umount call. V2 adds a patch that fixes the order of the aio teardown. The addition of the NFS umount call unmasked that bug.

Peter Lieven (2):
block/nfs: tear down aio before nfs_close
block/nfs: add support for nfs_umount

 block/nfs.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 1/2 block/nfs: tear down aio before nfs_close

nfs_close is a sync call from libnfs and has its own event handler polling on the nfs FD. Avoid that both QEMU and libnfs are intefering here.

---
 block/nfs.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
block/nfs.c +4 -2
index 0ec50953e4..2c98508275 100644
@@ -390,12 +390,14 @@ static void nfs_attach_aio_context(BlockDriverState *bs,
 static void nfs_client_close(NFSClient *client)
 {
     if (client->context) {
+        qemu_mutex_lock(&client->mutex);
+        aio_set_fd_handler(client->aio_context, nfs_get_fd(client->context),
+                           false, NULL, NULL, NULL, NULL);
+        qemu_mutex_unlock(&client->mutex);
         if (client->fh) {
             nfs_close(client->context, client->fh);
             client->fh = NULL;
         }
-        aio_set_fd_handler(client->aio_context, nfs_get_fd(client->context),
-                           false, NULL, NULL, NULL, NULL);
         nfs_destroy_context(client->context);
         client->context = NULL;
     }
Signature · 1 line
2.17.1
#2 lore raw

Re: [Qemu-devel] [PATCH V2 1/2] block/nfs: tear down aio before nfs_close

Quoted 9 lines · Peter Lieven

nfs_close is a sync call from libnfs and has its own event handler polling on the nfs FD. Avoid that both QEMU and libnfs are intefering here.

---
 block/nfs.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

I’ve just seen that Kevin has already included the second patch (in its v1) in his pull request.

So all that I can do is take this patch, which sounds good to me, especially since Ronnie has agreed that we should remove our FD handler there.

(So I’ve rebased the patch on top of Kevin’s pull request, and I’ve taken it to my block branch.)

Max

#3 lore raw

Re: [Qemu-devel] [PATCH V2 1/2] block/nfs: tear down aio before nfs_close

Am 13.09.19 um 11:51 schrieb Max Reitz:

Quoted 13 lines · Peter Lieven
Quoted 9 lines

nfs_close is a sync call from libnfs and has its own event handler polling on the nfs FD. Avoid that both QEMU and libnfs are intefering here.

---
 block/nfs.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

I’ve just seen that Kevin has already included the second patch (in its v1) in his pull request.

Quoted 6 lines

So all that I can do is take this patch, which sounds good to me, especially since Ronnie has agreed that we should remove our FD handler there.

(So I’ve rebased the patch on top of Kevin’s pull request, and I’ve taken it to my block branch.)

Thank you. After I discovered that we had this bug also before I added the nfs_umount call I thought

it would be good to have this patch first and the add the umount call because the fix should also go into

stable because in theory we could also run into trouble with just the *sync* nfs_clsoe call.

Peter

#4 lore raw

Re: [Qemu-devel] [PATCH V2 1/2] block/nfs: tear down aio before nfs_close

In reply to Max Reitz

Am 13.09.2019 um 11:51 hat Max Reitz geschrieben:

Quoted 5 lines · Peter Lieven
Quoted 4 lines

nfs_close is a sync call from libnfs and has its own event handler polling on the nfs FD. Avoid that both QEMU and libnfs are intefering here.

Quoted 8 lines
Quoted 5 lines
---
 block/nfs.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

I’ve just seen that Kevin has already included the second patch (in its v1) in his pull request.

Oops, sorry about this. Peter hasn't pulled yet, so I'll update the tag for the pull request. Let's see which version gets merged in the end.

Kevin

#5 lore raw

PATCH v2 2/2 block/nfs: add support for nfs_umount

In reply to Peter Lieven

libnfs recently added support for unmounting. Add support in Qemu too.

---
 block/nfs.c | 3 +++
 1 file changed, 3 insertions(+)
block/nfs.c +3 -0
index 2c98508275..f39acfdb28 100644
@@ -398,6 +398,9 @@ static void nfs_client_close(NFSClient *client)
             nfs_close(client->context, client->fh);
             client->fh = NULL;
         }
+#ifdef LIBNFS_FEATURE_UMOUNT
+        nfs_umount(client->context);
+#endif
         nfs_destroy_context(client->context);
         client->context = NULL;
     }
Signature · 1 line
2.17.1
#6 lore raw

Re: [Qemu-devel] [PATCH V2 2/2] block/nfs: add support for nfs_umount

Quoted 13 lines · Peter Lieven

libnfs recently added support for unmounting. Add support in Qemu too.

---
 block/nfs.c | 3 +++
 1 file changed, 3 insertions(+)
block/nfs.c +0 -0
index 2c98508275..f39acfdb28 100644

block/nfs.c static void nfs_client_close(NFSClient *client) · line 406

Quoted 9 lines
block/nfs.c +3 -0
@@ -398,6 +398,9 @@ static void nfs_client_close(NFSClient *client)
             nfs_close(client->context, client->fh);
             client->fh = NULL;
         }
+#ifdef LIBNFS_FEATURE_UMOUNT
+        nfs_umount(client->context);
+#endif
         nfs_destroy_context(client->context);
         client->context = NULL;
     }

I don’t understand what unmounting means in this context. Is it just generic clean-up for NFSv3 (it appears that it’s a no-op for NFSv4)? Why isn’t that done by nfs_destroy_context()?

Max

#7 lore raw

Re: [Qemu-devel] [PATCH V2 2/2] block/nfs: add support for nfs_umount

Am 11.09.19 um 09:48 schrieb Max Reitz:

Quoted 9 lines · Peter Lieven
Quoted 8 lines

libnfs recently added support for unmounting. Add support in Qemu too.

---
 block/nfs.c | 3 +++
 1 file changed, 3 insertions(+)
Quoted 16 lines
Quoted 5 lines
block/nfs.c +0 -0
index 2c98508275..f39acfdb28 100644

block/nfs.c static void nfs_client_close(NFSClient *client) · line 406

Quoted 9 lines
block/nfs.c +3 -0
@@ -398,6 +398,9 @@ static void nfs_client_close(NFSClient *client)
             nfs_close(client->context, client->fh);
             client->fh = NULL;
         }
+#ifdef LIBNFS_FEATURE_UMOUNT
+        nfs_umount(client->context);
+#endif
         nfs_destroy_context(client->context);
         client->context = NULL;
     }

I don’t understand what unmounting means in this context. Is it just generic clean-up for NFSv3 (it appears that it’s a no-op for NFSv4)?

Its a call to the mount daemon on the NFSv3 server. It will effectively

cause that the connection is no longer listed when showmounts -a is issued on the server.

Quoted 1 line

Why isn’t that done by nfs_destroy_context()?

That would have been the right place, but libnfs added support for this call only recently. I think with version 4.0.0

Peter

#8 lore raw

Re: [Qemu-devel] [PATCH V2 2/2] block/nfs: add support for nfs_umount

In reply to Max Reitz
Quoted 20 lines · Max Reitz
Quoted 18 lines · Peter Lieven

libnfs recently added support for unmounting. Add support in Qemu too.

---
 block/nfs.c | 3 +++
 1 file changed, 3 insertions(+)
block/nfs.c +2 -0
index 2c98508275..f39acfdb28 100644
@@ -398,6 +398,9 @@ static void nfs_client_close(NFSClient *client)
             nfs_close(client->context, client->fh);
             client->fh = NULL;
         }
+#ifdef LIBNFS_FEATURE_UMOUNT
+        nfs_umount(client->context);
Quoted 8 lines

block/nfs.c static void nfs_client_close(NFSClient *client) · line 406

Quoted 4 lines
block/nfs.c +1 -0
+#endif
         nfs_destroy_context(client->context);
         client->context = NULL;
     }

I don’t understand what unmounting means in this context. Is it just generic clean-up for NFSv3 (it appears that it’s a no-op for NFSv4)? Why isn’t that done by nfs_destroy_context()?

Umount is weird since there isn't actually any state in NFSv3 and "mounting" in nfsv3 is really just a matter of converting the path to be mounted into a filehandle.
That is all the mount protocol is really used for.

This is all handled in a separate protocol/server called rpc.mountd that is separate from NFSd. Running as a different process and listening to a different port.
And the only purpose of rpc.mountd is to take a path to a share and return a nfsv3 filehandle to the root of that path.
As a side-effect, rpc.mountd also keeps track of which clients have called MNT but not yet UMNT and thus showmount -a
can give a lost of all client that have "mounted" the share but not yet called "UMNT".

It has no effect at all on NFSv3 and is purely cosmetic. This ONLY affects "showmount -a" output.
NFSv4 does away with all these separate protocols such as mount, statd, nlm and even portmapper
so there is not even a concept of showmount -a for nfsv4.

As the libnfs maintainer, why did I do nfs_umount() the way I did? First of all, I think of nfs UMNT as really just cosmetic and didn't want to put too much work into it. But people wanted it.

I implemented it as a sync function since I think few people would actually use it at all and it meant that I just didn't have to invest in having to build an async piupelinje.

I did NOT implement it inside nfs_destroy_context() since that function is supposed to be, in my view, non-blocking andn should just tear the connection and immediately return.
As unmount would be
* close the tcp socket to the nfs server
* open new socket to portmapper and ask "where is rpc.mountd"
* close socket to portmapper, then open new socket to rpc.mountd
* tell rpc.mountd to remove us from the showmount -a list
* close socket

I just took the cheap and easy path. Do it as a sync function with my own eventloop.

Again, UMNT has no real effect on anything related to NFS except what showmount -a will return. That is one big reason why
I was just not much motivated enough to build it as an async function.

Once we all switch to NFSv4 this will all be moot since the MOUNT protocol no longer exists and neither does rpc.mountd.

Quoted 3 lines

Max

#9 lore raw

Re: [Qemu-devel] [PATCH V2 2/2] block/nfs: add support for nfs_umount

Quoted 73 lines · ronnie sahlberg
Quoted 20 lines · Max Reitz
Quoted 18 lines · Peter Lieven

libnfs recently added support for unmounting. Add support in Qemu too.

---
 block/nfs.c | 3 +++
 1 file changed, 3 insertions(+)
block/nfs.c +2 -0
index 2c98508275..f39acfdb28 100644
@@ -398,6 +398,9 @@ static void nfs_client_close(NFSClient *client)
             nfs_close(client->context, client->fh);
             client->fh = NULL;
         }
+#ifdef LIBNFS_FEATURE_UMOUNT
+        nfs_umount(client->context);
Quoted 8 lines

block/nfs.c static void nfs_client_close(NFSClient *client) · line 406

Quoted 4 lines
block/nfs.c +1 -0
+#endif
         nfs_destroy_context(client->context);
         client->context = NULL;
     }

I don’t understand what unmounting means in this context. Is it just generic clean-up for NFSv3 (it appears that it’s a no-op for NFSv4)? Why isn’t that done by nfs_destroy_context()?

Umount is weird since there isn't actually any state in NFSv3 and "mounting" in nfsv3 is really just a matter of converting the path to be mounted into a filehandle.
That is all the mount protocol is really used for.

This is all handled in a separate protocol/server called rpc.mountd that is separate from NFSd. Running as a different process and listening to a different port.
And the only purpose of rpc.mountd is to take a path to a share and return a nfsv3 filehandle to the root of that path.
As a side-effect, rpc.mountd also keeps track of which clients have called MNT but not yet UMNT and thus showmount -a
can give a lost of all client that have "mounted" the share but not yet called "UMNT".

It has no effect at all on NFSv3 and is purely cosmetic. This ONLY affects "showmount -a" output.
NFSv4 does away with all these separate protocols such as mount, statd, nlm and even portmapper
so there is not even a concept of showmount -a for nfsv4.

As the libnfs maintainer, why did I do nfs_umount() the way I did? First of all, I think of nfs UMNT as really just cosmetic and didn't want to put too much work into it. But people wanted it.

I implemented it as a sync function since I think few people would actually use it at all and it meant that I just didn't have to invest in having to build an async piupelinje.

I did NOT implement it inside nfs_destroy_context() since that function is supposed to be, in my view, non-blocking andn should just tear the connection and immediately return.
As unmount would be
* close the tcp socket to the nfs server
* open new socket to portmapper and ask "where is rpc.mountd"
* close socket to portmapper, then open new socket to rpc.mountd
* tell rpc.mountd to remove us from the showmount -a list
* close socket

I just took the cheap and easy path. Do it as a sync function with my own eventloop.

Quoted 6 lines

Again, UMNT has no real effect on anything related to NFS except what showmount -a will return. That is one big reason why
I was just not much motivated enough to build it as an async function.

Once we all switch to NFSv4 this will all be moot since the MOUNT protocol no longer exists and neither does rpc.mountd.

OK. Thanks a lot for the detailed explanation! :-)

Max