SUNRPC: skip dead but not buried clients on PipeFS events
Subsystems (3)
PATCH v2 1/1 SUNRPC: skip dead but not buried clients on PipeFS events
v2: atomic_inc_return() was replaced by atomic_inc_not_zero().
These clients can't be safely dereferenced if their counter in 0.
--- net/sunrpc/clnt.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)
net/sunrpc/clnt.c +2 -1
@@ -218,7 +218,8 @@ static struct rpc_clnt *rpc_get_client_for_event(struct net *net, int event)if (((event ==RPC_PIPEFS_MOUNT ) && clnt->cl_dentry) || ((event ==RPC_PIPEFS_UMOUNT ) && !clnt->cl_dentry))continue ; -atomic_inc (&clnt->cl_count); +if (atomic_inc_not_zero (&clnt->cl_count) ==0 ) +continue ;spin_unlock (&sn->rpc_client_lock);return clnt; }
Quoted 3 lines · Stanislav Kinsbursky
v2:
atomic_inc_return()was replaced byatomic_inc_not_zero().These clients can't be safely dereferenced if their counter in 0.
I'm pretty confused by how these notifiers work....
rpc_release_client decrements cl_count to zero temporarily, to have it immediately re-incremented by rpc_free_auth.
So if we're called concurrently with rpc_release_client then it's sort of random whether someone gets this callback.
Is that a problem?
Also, is this an existing bug? (In which case Trond should take it now.)
--b.
Quoted 22 lines
Signed-off-by Stanislav Kinsbursky <[email protected]>--- net/sunrpc/clnt.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)net/sunrpc/clnt.c +2
-1@@ -218,7 +218,8 @@ static struct rpc_clnt *rpc_get_client_for_event(struct net *net, int event)if (((event ==RPC_PIPEFS_MOUNT ) && clnt->cl_dentry) || ((event ==RPC_PIPEFS_UMOUNT ) && !clnt->cl_dentry))continue ; -atomic_inc (&clnt->cl_count); +if (atomic_inc_not_zero (&clnt->cl_count) ==0 ) +continue ;spin_unlock (&sn->rpc_client_lock);return clnt; }
T24gV2VkLCAyMDEyLTA0LTI1IGF0IDEzOjMwIC0wNDAwLCBKLiBCcnVjZSBGaWVsZHMgd3JvdGU6 DQo+IE9uIEZyaSwgQXByIDIwLCAyMDEyIGF0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BzaW1wbHkgbW92ZSB0aGUgY2FsbCB0byBycGNfdW5yZWdpc3Rl cl9jbGllbnQoKQ0KaW50byBycGNfZnJlZV9hdXRoKCkgc28gdGhhdCB0aGUgcGlwZWZzIG5vdGlm aWVyIGRvZXNuJ3Qgc2VlIHVzLCBvciB3ZQ0KY291bGQgc2V0IGEgZmxhZyB0byBoYXZlIGl0IGln bm9yZSB1cy4NCg0KPiBBbHNvLCBpcyB0aGlzIGFuIGV4aXN0aW5nIGJ1Zz8gIChJbiB3aGljaCBj YXNlIFRyb25kIHNob3VsZCB0YWtlIGl0DQo+IG5vdy4pDQoNCg0KLS0gDQpUcm9uZCBNeWtsZWJ1 c3QNCkxpbnV4IE5GUyBjbGllbnQgbWFpbnRhaW5lcg0KDQpOZXRBcHANClRyb25kLk15a2xlYnVz dEBuZXRhcHAuY29tDQp3d3cubmV0YXBwLmNvbQ0KDQo=
25.04.2012 21:30, J. Bruce Fields написал:
Quoted 5 lines · Stanislav Kinsbursky
Quoted 3 lines
v2:
atomic_inc_return()was replaced byatomic_inc_not_zero().These clients can't be safely dereferenced if their counter in 0.
I'm pretty confused by how these notifiers work....
There were made as simple as possible - i.e. notifier holds a client while creating of destroying PipeFS dentries. But event in this case there were races.
Quoted 2 lines
rpc_release_clientdecrementscl_countto zero temporarily, to have it immediately re-incremented byrpc_free_auth.
BTW, I'm really confused with these re-incrementing reference counter technic. It makes life-time of RPC client unpredictable.
Is this a real-world valid situation, when usage of it reached zero, but while we destroying auth, there can some other user of client appear and client become alive again?
It it was done just to make sure that client is still active while we destroying auth, then maybe we can just remove the client from the clients list before rpc_free_auth? It will simplify the notifier callback logic greatly...
Quoted 7 lines
So if we're called concurrently with
rpc_release_clientthen it's sort of random whether someone gets this callback.Is that a problem?
Also, is this an existing bug? (In which case Trond should take it now.)
This is probably not a bug (I can't llok at the code right now; because these dentries will be destroyed), but a flaw.
Today (without this patch) notifier can try to create dentries for clients, which are dead already (i.e. auth was destroyed and client is going to be destroyed very soon, but notifier gained lock first.
Quoted 24 lines
--b.
Quoted 21 lines
Signed-off-by Stanislav Kinsbursky<[email protected]>--- net/sunrpc/clnt.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-)net/sunrpc/clnt.c +2
-1@@ -218,7 +218,8 @@ static struct rpc_clnt *rpc_get_client_for_event(struct net *net, int event)if (((event ==RPC_PIPEFS_MOUNT )&& clnt->cl_dentry) || ((event ==RPC_PIPEFS_UMOUNT )&& !clnt->cl_dentry))continue ; -atomic_inc (&clnt->cl_count); +if (atomic_inc_not_zero (&clnt->cl_count) ==0 ) +continue ;spin_unlock (&sn->rpc_client_lock);return clnt; }
25.04.2012 21:30, J. Bruce Fields написал:
Quoted 9 lines · Stanislav Kinsbursky
Quoted 3 lines
v2:
atomic_inc_return()was replaced byatomic_inc_not_zero().These clients can't be safely dereferenced if their counter in 0.
I'm pretty confused by how these notifiers work....
rpc_release_clientdecrementscl_countto zero temporarily, to have it immediately re-incremented byrpc_free_auth.
Quoted 7 lines
So if we're called concurrently with
rpc_release_clientthen it's sort of random whether someone gets this callback.Is that a problem?
Also, is this an existing bug? (In which case Trond should take it now.)
Sorry, I was mistaken in previous letter.
Yes, this is an existent bug.
I.e. without this patch notifier can dereference a client, which is actually dead already, but haven't deleted itself from the client's list. And then notifier will try to work with this client and even release it at the end.