@@ -1144,6 +1144,7 @@ void pnfs_layoutreturn_free_lsegs(struct pnfs_layout_hdr *lo,
1144
1144
static bool
1145
1145
pnfs_prepare_layoutreturn (struct pnfs_layout_hdr * lo ,
1146
1146
nfs4_stateid * stateid ,
1147
+ const struct cred * * cred ,
1147
1148
enum pnfs_iomode * iomode )
1148
1149
{
1149
1150
/* Serialise LAYOUTGET/LAYOUTRETURN */
@@ -1154,18 +1155,17 @@ pnfs_prepare_layoutreturn(struct pnfs_layout_hdr *lo,
1154
1155
set_bit (NFS_LAYOUT_RETURN , & lo -> plh_flags );
1155
1156
pnfs_get_layout_hdr (lo );
1156
1157
if (test_bit (NFS_LAYOUT_RETURN_REQUESTED , & lo -> plh_flags )) {
1157
- if (stateid != NULL ) {
1158
- nfs4_stateid_copy (stateid , & lo -> plh_stateid );
1159
- if (lo -> plh_return_seq != 0 )
1160
- stateid -> seqid = cpu_to_be32 (lo -> plh_return_seq );
1161
- }
1158
+ nfs4_stateid_copy (stateid , & lo -> plh_stateid );
1159
+ * cred = get_cred (lo -> plh_lc_cred );
1160
+ if (lo -> plh_return_seq != 0 )
1161
+ stateid -> seqid = cpu_to_be32 (lo -> plh_return_seq );
1162
1162
if (iomode != NULL )
1163
1163
* iomode = lo -> plh_return_iomode ;
1164
1164
pnfs_clear_layoutreturn_info (lo );
1165
1165
return true;
1166
1166
}
1167
- if (stateid != NULL )
1168
- nfs4_stateid_copy ( stateid , & lo -> plh_stateid );
1167
+ nfs4_stateid_copy (stateid , & lo -> plh_stateid );
1168
+ * cred = get_cred ( lo -> plh_lc_cred );
1169
1169
if (iomode != NULL )
1170
1170
* iomode = IOMODE_ANY ;
1171
1171
return true;
@@ -1189,28 +1189,34 @@ pnfs_init_layoutreturn_args(struct nfs4_layoutreturn_args *args,
1189
1189
}
1190
1190
1191
1191
static int
1192
- pnfs_send_layoutreturn (struct pnfs_layout_hdr * lo , const nfs4_stateid * stateid ,
1193
- enum pnfs_iomode iomode , bool sync )
1192
+ pnfs_send_layoutreturn (struct pnfs_layout_hdr * lo ,
1193
+ const nfs4_stateid * stateid ,
1194
+ const struct cred * * pcred ,
1195
+ enum pnfs_iomode iomode ,
1196
+ bool sync )
1194
1197
{
1195
1198
struct inode * ino = lo -> plh_inode ;
1196
1199
struct pnfs_layoutdriver_type * ld = NFS_SERVER (ino )-> pnfs_curr_ld ;
1197
1200
struct nfs4_layoutreturn * lrp ;
1201
+ const struct cred * cred = * pcred ;
1198
1202
int status = 0 ;
1199
1203
1204
+ * pcred = NULL ;
1200
1205
lrp = kzalloc (sizeof (* lrp ), GFP_NOFS );
1201
1206
if (unlikely (lrp == NULL )) {
1202
1207
status = - ENOMEM ;
1203
1208
spin_lock (& ino -> i_lock );
1204
1209
pnfs_clear_layoutreturn_waitbit (lo );
1205
1210
spin_unlock (& ino -> i_lock );
1211
+ put_cred (cred );
1206
1212
pnfs_put_layout_hdr (lo );
1207
1213
goto out ;
1208
1214
}
1209
1215
1210
1216
pnfs_init_layoutreturn_args (& lrp -> args , lo , stateid , iomode );
1211
1217
lrp -> args .ld_private = & lrp -> ld_private ;
1212
1218
lrp -> clp = NFS_SERVER (ino )-> nfs_client ;
1213
- lrp -> cred = lo -> plh_lc_cred ;
1219
+ lrp -> cred = cred ;
1214
1220
if (ld -> prepare_layoutreturn )
1215
1221
ld -> prepare_layoutreturn (& lrp -> args );
1216
1222
@@ -1255,15 +1261,16 @@ static void pnfs_layoutreturn_before_put_layout_hdr(struct pnfs_layout_hdr *lo)
1255
1261
return ;
1256
1262
spin_lock (& inode -> i_lock );
1257
1263
if (pnfs_layout_need_return (lo )) {
1264
+ const struct cred * cred ;
1258
1265
nfs4_stateid stateid ;
1259
1266
enum pnfs_iomode iomode ;
1260
1267
bool send ;
1261
1268
1262
- send = pnfs_prepare_layoutreturn (lo , & stateid , & iomode );
1269
+ send = pnfs_prepare_layoutreturn (lo , & stateid , & cred , & iomode );
1263
1270
spin_unlock (& inode -> i_lock );
1264
1271
if (send ) {
1265
1272
/* Send an async layoutreturn so we dont deadlock */
1266
- pnfs_send_layoutreturn (lo , & stateid , iomode , false);
1273
+ pnfs_send_layoutreturn (lo , & stateid , & cred , iomode , false);
1267
1274
}
1268
1275
} else
1269
1276
spin_unlock (& inode -> i_lock );
@@ -1283,6 +1290,7 @@ _pnfs_return_layout(struct inode *ino)
1283
1290
struct pnfs_layout_hdr * lo = NULL ;
1284
1291
struct nfs_inode * nfsi = NFS_I (ino );
1285
1292
LIST_HEAD (tmp_list );
1293
+ const struct cred * cred ;
1286
1294
nfs4_stateid stateid ;
1287
1295
int status = 0 ;
1288
1296
bool send , valid_layout ;
@@ -1327,10 +1335,10 @@ _pnfs_return_layout(struct inode *ino)
1327
1335
goto out_put_layout_hdr ;
1328
1336
}
1329
1337
1330
- send = pnfs_prepare_layoutreturn (lo , & stateid , NULL );
1338
+ send = pnfs_prepare_layoutreturn (lo , & stateid , & cred , NULL );
1331
1339
spin_unlock (& ino -> i_lock );
1332
1340
if (send )
1333
- status = pnfs_send_layoutreturn (lo , & stateid , IOMODE_ANY , true);
1341
+ status = pnfs_send_layoutreturn (lo , & stateid , & cred , IOMODE_ANY , true);
1334
1342
out_put_layout_hdr :
1335
1343
pnfs_free_lseg_list (& tmp_list );
1336
1344
pnfs_put_layout_hdr (lo );
@@ -1376,6 +1384,7 @@ bool pnfs_roc(struct inode *ino,
1376
1384
struct nfs4_state * state ;
1377
1385
struct pnfs_layout_hdr * lo ;
1378
1386
struct pnfs_layout_segment * lseg , * next ;
1387
+ const struct cred * lc_cred ;
1379
1388
nfs4_stateid stateid ;
1380
1389
enum pnfs_iomode iomode = 0 ;
1381
1390
bool layoutreturn = false, roc = false;
@@ -1445,16 +1454,20 @@ bool pnfs_roc(struct inode *ino,
1445
1454
* 2. we don't send layoutreturn
1446
1455
*/
1447
1456
/* lo ref dropped in pnfs_roc_release() */
1448
- layoutreturn = pnfs_prepare_layoutreturn (lo , & stateid , & iomode );
1457
+ layoutreturn = pnfs_prepare_layoutreturn (lo , & stateid , & lc_cred , & iomode );
1449
1458
/* If the creds don't match, we can't compound the layoutreturn */
1450
- if (!layoutreturn || cred_fscmp ( cred , lo -> plh_lc_cred ) != 0 )
1459
+ if (!layoutreturn )
1451
1460
goto out_noroc ;
1461
+ if (cred_fscmp (cred , lc_cred ) != 0 )
1462
+ goto out_noroc_put_cred ;
1452
1463
1453
1464
roc = layoutreturn ;
1454
1465
pnfs_init_layoutreturn_args (args , lo , & stateid , iomode );
1455
1466
res -> lrs_present = 0 ;
1456
1467
layoutreturn = false;
1457
1468
1469
+ out_noroc_put_cred :
1470
+ put_cred (lc_cred );
1458
1471
out_noroc :
1459
1472
spin_unlock (& ino -> i_lock );
1460
1473
rcu_read_unlock ();
@@ -1467,7 +1480,7 @@ bool pnfs_roc(struct inode *ino,
1467
1480
return true;
1468
1481
}
1469
1482
if (layoutreturn )
1470
- pnfs_send_layoutreturn (lo , & stateid , iomode , true);
1483
+ pnfs_send_layoutreturn (lo , & stateid , & lc_cred , iomode , true);
1471
1484
pnfs_put_layout_hdr (lo );
1472
1485
return false;
1473
1486
}
@@ -2464,13 +2477,14 @@ pnfs_mark_layout_for_return(struct inode *inode,
2464
2477
* for how it works.
2465
2478
*/
2466
2479
if (pnfs_mark_matching_lsegs_return (lo , & lo -> plh_return_segs , range , 0 ) != - EBUSY ) {
2480
+ const struct cred * cred ;
2467
2481
nfs4_stateid stateid ;
2468
2482
enum pnfs_iomode iomode ;
2469
2483
2470
- return_now = pnfs_prepare_layoutreturn (lo , & stateid , & iomode );
2484
+ return_now = pnfs_prepare_layoutreturn (lo , & stateid , & cred , & iomode );
2471
2485
spin_unlock (& inode -> i_lock );
2472
2486
if (return_now )
2473
- pnfs_send_layoutreturn (lo , & stateid , iomode , false);
2487
+ pnfs_send_layoutreturn (lo , & stateid , & cred , iomode , false);
2474
2488
} else {
2475
2489
spin_unlock (& inode -> i_lock );
2476
2490
nfs_commit_inode (inode , 0 );
0 commit comments