aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfs/write.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/nfs/write.c')
-rw-r--r--fs/nfs/write.c55
1 files changed, 36 insertions, 19 deletions
diff --git a/fs/nfs/write.c b/fs/nfs/write.c
index de38d63aa920..3aea3ca98ab7 100644
--- a/fs/nfs/write.c
+++ b/fs/nfs/write.c
@@ -1201,6 +1201,25 @@ int nfs_writeback_done(struct rpc_task *task, struct nfs_write_data *data)
1201 1201
1202 1202
1203#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4) 1203#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
1204static int nfs_commit_set_lock(struct nfs_inode *nfsi, int may_wait)
1205{
1206 if (!test_and_set_bit(NFS_INO_COMMIT, &nfsi->flags))
1207 return 1;
1208 if (may_wait && !out_of_line_wait_on_bit_lock(&nfsi->flags,
1209 NFS_INO_COMMIT, nfs_wait_bit_killable,
1210 TASK_KILLABLE))
1211 return 1;
1212 return 0;
1213}
1214
1215static void nfs_commit_clear_lock(struct nfs_inode *nfsi)
1216{
1217 clear_bit(NFS_INO_COMMIT, &nfsi->flags);
1218 smp_mb__after_clear_bit();
1219 wake_up_bit(&nfsi->flags, NFS_INO_COMMIT);
1220}
1221
1222
1204static void nfs_commitdata_release(void *data) 1223static void nfs_commitdata_release(void *data)
1205{ 1224{
1206 struct nfs_write_data *wdata = data; 1225 struct nfs_write_data *wdata = data;
@@ -1262,8 +1281,6 @@ static int nfs_commit_rpcsetup(struct list_head *head,
1262 task = rpc_run_task(&task_setup_data); 1281 task = rpc_run_task(&task_setup_data);
1263 if (IS_ERR(task)) 1282 if (IS_ERR(task))
1264 return PTR_ERR(task); 1283 return PTR_ERR(task);
1265 if (how & FLUSH_SYNC)
1266 rpc_wait_for_completion_task(task);
1267 rpc_put_task(task); 1284 rpc_put_task(task);
1268 return 0; 1285 return 0;
1269} 1286}
@@ -1294,6 +1311,7 @@ nfs_commit_list(struct inode *inode, struct list_head *head, int how)
1294 BDI_RECLAIMABLE); 1311 BDI_RECLAIMABLE);
1295 nfs_clear_page_tag_locked(req); 1312 nfs_clear_page_tag_locked(req);
1296 } 1313 }
1314 nfs_commit_clear_lock(NFS_I(inode));
1297 return -ENOMEM; 1315 return -ENOMEM;
1298} 1316}
1299 1317
@@ -1349,6 +1367,7 @@ static void nfs_commit_release(void *calldata)
1349 next: 1367 next:
1350 nfs_clear_page_tag_locked(req); 1368 nfs_clear_page_tag_locked(req);
1351 } 1369 }
1370 nfs_commit_clear_lock(NFS_I(data->inode));
1352 nfs_commitdata_release(calldata); 1371 nfs_commitdata_release(calldata);
1353} 1372}
1354 1373
@@ -1363,8 +1382,11 @@ static const struct rpc_call_ops nfs_commit_ops = {
1363static int nfs_commit_inode(struct inode *inode, int how) 1382static int nfs_commit_inode(struct inode *inode, int how)
1364{ 1383{
1365 LIST_HEAD(head); 1384 LIST_HEAD(head);
1366 int res; 1385 int may_wait = how & FLUSH_SYNC;
1386 int res = 0;
1367 1387
1388 if (!nfs_commit_set_lock(NFS_I(inode), may_wait))
1389 goto out;
1368 spin_lock(&inode->i_lock); 1390 spin_lock(&inode->i_lock);
1369 res = nfs_scan_commit(inode, &head, 0, 0); 1391 res = nfs_scan_commit(inode, &head, 0, 0);
1370 spin_unlock(&inode->i_lock); 1392 spin_unlock(&inode->i_lock);
@@ -1372,7 +1394,13 @@ static int nfs_commit_inode(struct inode *inode, int how)
1372 int error = nfs_commit_list(inode, &head, how); 1394 int error = nfs_commit_list(inode, &head, how);
1373 if (error < 0) 1395 if (error < 0)
1374 return error; 1396 return error;
1375 } 1397 if (may_wait)
1398 wait_on_bit(&NFS_I(inode)->flags, NFS_INO_COMMIT,
1399 nfs_wait_bit_killable,
1400 TASK_KILLABLE);
1401 } else
1402 nfs_commit_clear_lock(NFS_I(inode));
1403out:
1376 return res; 1404 return res;
1377} 1405}
1378 1406
@@ -1444,6 +1472,7 @@ int nfs_wb_page_cancel(struct inode *inode, struct page *page)
1444 1472
1445 BUG_ON(!PageLocked(page)); 1473 BUG_ON(!PageLocked(page));
1446 for (;;) { 1474 for (;;) {
1475 wait_on_page_writeback(page);
1447 req = nfs_page_find_request(page); 1476 req = nfs_page_find_request(page);
1448 if (req == NULL) 1477 if (req == NULL)
1449 break; 1478 break;
@@ -1478,30 +1507,18 @@ int nfs_wb_page(struct inode *inode, struct page *page)
1478 .range_start = range_start, 1507 .range_start = range_start,
1479 .range_end = range_end, 1508 .range_end = range_end,
1480 }; 1509 };
1481 struct nfs_page *req;
1482 int need_commit;
1483 int ret; 1510 int ret;
1484 1511
1485 while(PagePrivate(page)) { 1512 while(PagePrivate(page)) {
1513 wait_on_page_writeback(page);
1486 if (clear_page_dirty_for_io(page)) { 1514 if (clear_page_dirty_for_io(page)) {
1487 ret = nfs_writepage_locked(page, &wbc); 1515 ret = nfs_writepage_locked(page, &wbc);
1488 if (ret < 0) 1516 if (ret < 0)
1489 goto out_error; 1517 goto out_error;
1490 } 1518 }
1491 req = nfs_find_and_lock_request(page); 1519 ret = sync_inode(inode, &wbc);
1492 if (!req) 1520 if (ret < 0)
1493 break;
1494 if (IS_ERR(req)) {
1495 ret = PTR_ERR(req);
1496 goto out_error; 1521 goto out_error;
1497 }
1498 need_commit = test_bit(PG_CLEAN, &req->wb_flags);
1499 nfs_clear_page_tag_locked(req);
1500 if (need_commit) {
1501 ret = nfs_commit_inode(inode, FLUSH_SYNC);
1502 if (ret < 0)
1503 goto out_error;
1504 }
1505 } 1522 }
1506 return 0; 1523 return 0;
1507out_error: 1524out_error: