Skip to content

Commit 4aa17d0

Browse files
Trond Myklebustgregkh
authored andcommitted
NFSv4/pNFS: Don't call _nfs4_pnfs_v3_ds_connect multiple times
[ Upstream commit f46f849 ] After we grab the lock in nfs4_pnfs_ds_connect(), there is no check for whether or not ds->ds_clp has already been initialised, so we can end up adding the same transports multiple times. Fixes: fc821d5 ("pnfs/NFSv4.1: Add multipath capabilities to pNFS flexfiles servers over NFSv3") Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 885c0cc commit 4aa17d0

1 file changed

Lines changed: 26 additions & 26 deletions

File tree

‎fs/nfs/pnfs_nfs.c‎

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -791,19 +791,16 @@ nfs4_pnfs_ds_add(struct list_head *dsaddrs, gfp_t gfp_flags)
791791
}
792792
EXPORT_SYMBOL_GPL(nfs4_pnfs_ds_add);
793793

794-
static void nfs4_wait_ds_connect(struct nfs4_pnfs_ds *ds)
794+
static int nfs4_wait_ds_connect(struct nfs4_pnfs_ds *ds)
795795
{
796796
might_sleep();
797-
wait_on_bit(&ds->ds_state, NFS4DS_CONNECTING,
798-
TASK_KILLABLE);
797+
return wait_on_bit(&ds->ds_state, NFS4DS_CONNECTING, TASK_KILLABLE);
799798
}
800799

801800
static void nfs4_clear_ds_conn_bit(struct nfs4_pnfs_ds *ds)
802801
{
803802
smp_mb__before_atomic();
804-
clear_bit(NFS4DS_CONNECTING, &ds->ds_state);
805-
smp_mb__after_atomic();
806-
wake_up_bit(&ds->ds_state, NFS4DS_CONNECTING);
803+
clear_and_wake_up_bit(NFS4DS_CONNECTING, &ds->ds_state);
807804
}
808805

809806
static struct nfs_client *(*get_v3_ds_connect)(
@@ -969,30 +966,33 @@ int nfs4_pnfs_ds_connect(struct nfs_server *mds_srv, struct nfs4_pnfs_ds *ds,
969966
{
970967
int err;
971968

972-
again:
973-
err = 0;
974-
if (test_and_set_bit(NFS4DS_CONNECTING, &ds->ds_state) == 0) {
975-
if (version == 3) {
976-
err = _nfs4_pnfs_v3_ds_connect(mds_srv, ds, timeo,
977-
retrans);
978-
} else if (version == 4) {
979-
err = _nfs4_pnfs_v4_ds_connect(mds_srv, ds, timeo,
980-
retrans, minor_version);
981-
} else {
982-
dprintk("%s: unsupported DS version %d\n", __func__,
983-
version);
984-
err = -EPROTONOSUPPORT;
985-
}
969+
do {
970+
err = nfs4_wait_ds_connect(ds);
971+
if (err || ds->ds_clp)
972+
goto out;
973+
if (nfs4_test_deviceid_unavailable(devid))
974+
return -ENODEV;
975+
} while (test_and_set_bit(NFS4DS_CONNECTING, &ds->ds_state) != 0);
986976

987-
nfs4_clear_ds_conn_bit(ds);
988-
} else {
989-
nfs4_wait_ds_connect(ds);
977+
if (ds->ds_clp)
978+
goto connect_done;
990979

991-
/* what was waited on didn't connect AND didn't mark unavail */
992-
if (!ds->ds_clp && !nfs4_test_deviceid_unavailable(devid))
993-
goto again;
980+
switch (version) {
981+
case 3:
982+
err = _nfs4_pnfs_v3_ds_connect(mds_srv, ds, timeo, retrans);
983+
break;
984+
case 4:
985+
err = _nfs4_pnfs_v4_ds_connect(mds_srv, ds, timeo, retrans,
986+
minor_version);
987+
break;
988+
default:
989+
dprintk("%s: unsupported DS version %d\n", __func__, version);
990+
err = -EPROTONOSUPPORT;
994991
}
995992

993+
connect_done:
994+
nfs4_clear_ds_conn_bit(ds);
995+
out:
996996
/*
997997
* At this point the ds->ds_clp should be ready, but it might have
998998
* hit an error.

0 commit comments

Comments
 (0)