write.c (8fe5f56c8a203a7a83d1b621c369655d914f3752) | write.c (0b7c01533aa9f4a228d07d2768d084acb3a387bc) |
---|---|
1/* 2 * linux/fs/nfs/write.c 3 * 4 * Write file data over NFS. 5 * 6 * Copyright (C) 1996, 1997, Olaf Kirch <okir@monad.swb.de> 7 */ 8 --- 34 unchanged lines hidden (view full) --- 43 struct inode *inode, int ioflags); 44static void nfs_redirty_request(struct nfs_page *req); 45static const struct rpc_call_ops nfs_write_partial_ops; 46static const struct rpc_call_ops nfs_write_full_ops; 47static const struct rpc_call_ops nfs_commit_ops; 48 49static struct kmem_cache *nfs_wdata_cachep; 50static mempool_t *nfs_wdata_mempool; | 1/* 2 * linux/fs/nfs/write.c 3 * 4 * Write file data over NFS. 5 * 6 * Copyright (C) 1996, 1997, Olaf Kirch <okir@monad.swb.de> 7 */ 8 --- 34 unchanged lines hidden (view full) --- 43 struct inode *inode, int ioflags); 44static void nfs_redirty_request(struct nfs_page *req); 45static const struct rpc_call_ops nfs_write_partial_ops; 46static const struct rpc_call_ops nfs_write_full_ops; 47static const struct rpc_call_ops nfs_commit_ops; 48 49static struct kmem_cache *nfs_wdata_cachep; 50static mempool_t *nfs_wdata_mempool; |
51static struct kmem_cache *nfs_cdata_cachep; |
|
51static mempool_t *nfs_commit_mempool; 52 | 52static mempool_t *nfs_commit_mempool; 53 |
53struct nfs_write_data *nfs_commitdata_alloc(void) | 54struct nfs_commit_data *nfs_commitdata_alloc(void) |
54{ | 55{ |
55 struct nfs_write_data *p = mempool_alloc(nfs_commit_mempool, GFP_NOFS); | 56 struct nfs_commit_data *p = mempool_alloc(nfs_commit_mempool, GFP_NOFS); |
56 57 if (p) { 58 memset(p, 0, sizeof(*p)); 59 INIT_LIST_HEAD(&p->pages); 60 } 61 return p; 62} 63EXPORT_SYMBOL_GPL(nfs_commitdata_alloc); 64 | 57 58 if (p) { 59 memset(p, 0, sizeof(*p)); 60 INIT_LIST_HEAD(&p->pages); 61 } 62 return p; 63} 64EXPORT_SYMBOL_GPL(nfs_commitdata_alloc); 65 |
65void nfs_commit_free(struct nfs_write_data *p) | 66void nfs_commit_free(struct nfs_commit_data *p) |
66{ | 67{ |
67 if (p && (p->pagevec != &p->page_array[0])) 68 kfree(p->pagevec); | |
69 mempool_free(p, nfs_commit_mempool); 70} 71EXPORT_SYMBOL_GPL(nfs_commit_free); 72 73struct nfs_write_data *nfs_writedata_alloc(unsigned int pagecount) 74{ 75 struct nfs_write_data *p = mempool_alloc(nfs_wdata_mempool, GFP_NOFS); 76 --- 1097 unchanged lines hidden (view full) --- 1174} 1175 1176void nfs_write_prepare(struct rpc_task *task, void *calldata) 1177{ 1178 struct nfs_write_data *data = calldata; 1179 NFS_PROTO(data->inode)->write_rpc_prepare(task, data); 1180} 1181 | 68 mempool_free(p, nfs_commit_mempool); 69} 70EXPORT_SYMBOL_GPL(nfs_commit_free); 71 72struct nfs_write_data *nfs_writedata_alloc(unsigned int pagecount) 73{ 74 struct nfs_write_data *p = mempool_alloc(nfs_wdata_mempool, GFP_NOFS); 75 --- 1097 unchanged lines hidden (view full) --- 1173} 1174 1175void nfs_write_prepare(struct rpc_task *task, void *calldata) 1176{ 1177 struct nfs_write_data *data = calldata; 1178 NFS_PROTO(data->inode)->write_rpc_prepare(task, data); 1179} 1180 |
1181void nfs_commit_prepare(struct rpc_task *task, void *calldata) 1182{ 1183 struct nfs_commit_data *data = calldata; 1184 1185 NFS_PROTO(data->inode)->commit_rpc_prepare(task, data); 1186} 1187 |
|
1182static const struct rpc_call_ops nfs_write_partial_ops = { 1183 .rpc_call_prepare = nfs_write_prepare, 1184 .rpc_call_done = nfs_writeback_done_partial, 1185 .rpc_release = nfs_writeback_release_partial, 1186}; 1187 1188/* 1189 * Handle a write reply that flushes a whole page. --- 160 unchanged lines hidden (view full) --- 1350void nfs_commit_clear_lock(struct nfs_inode *nfsi) 1351{ 1352 clear_bit(NFS_INO_COMMIT, &nfsi->flags); 1353 smp_mb__after_clear_bit(); 1354 wake_up_bit(&nfsi->flags, NFS_INO_COMMIT); 1355} 1356EXPORT_SYMBOL_GPL(nfs_commit_clear_lock); 1357 | 1188static const struct rpc_call_ops nfs_write_partial_ops = { 1189 .rpc_call_prepare = nfs_write_prepare, 1190 .rpc_call_done = nfs_writeback_done_partial, 1191 .rpc_release = nfs_writeback_release_partial, 1192}; 1193 1194/* 1195 * Handle a write reply that flushes a whole page. --- 160 unchanged lines hidden (view full) --- 1356void nfs_commit_clear_lock(struct nfs_inode *nfsi) 1357{ 1358 clear_bit(NFS_INO_COMMIT, &nfsi->flags); 1359 smp_mb__after_clear_bit(); 1360 wake_up_bit(&nfsi->flags, NFS_INO_COMMIT); 1361} 1362EXPORT_SYMBOL_GPL(nfs_commit_clear_lock); 1363 |
1358void nfs_commitdata_release(void *data) | 1364void nfs_commitdata_release(struct nfs_commit_data *data) |
1359{ | 1365{ |
1360 struct nfs_write_data *wdata = data; 1361 1362 put_nfs_open_context(wdata->args.context); 1363 nfs_commit_free(wdata); | 1366 put_nfs_open_context(data->context); 1367 nfs_commit_free(data); |
1364} 1365EXPORT_SYMBOL_GPL(nfs_commitdata_release); 1366 | 1368} 1369EXPORT_SYMBOL_GPL(nfs_commitdata_release); 1370 |
1367int nfs_initiate_commit(struct nfs_write_data *data, struct rpc_clnt *clnt, | 1371int nfs_initiate_commit(struct rpc_clnt *clnt, struct nfs_commit_data *data, |
1368 const struct rpc_call_ops *call_ops, 1369 int how) 1370{ 1371 struct rpc_task *task; 1372 int priority = flush_task_priority(how); 1373 struct rpc_message msg = { 1374 .rpc_argp = &data->args, 1375 .rpc_resp = &data->res, --- 22 unchanged lines hidden (view full) --- 1398 rpc_put_task(task); 1399 return 0; 1400} 1401EXPORT_SYMBOL_GPL(nfs_initiate_commit); 1402 1403/* 1404 * Set up the argument/result storage required for the RPC call. 1405 */ | 1372 const struct rpc_call_ops *call_ops, 1373 int how) 1374{ 1375 struct rpc_task *task; 1376 int priority = flush_task_priority(how); 1377 struct rpc_message msg = { 1378 .rpc_argp = &data->args, 1379 .rpc_resp = &data->res, --- 22 unchanged lines hidden (view full) --- 1402 rpc_put_task(task); 1403 return 0; 1404} 1405EXPORT_SYMBOL_GPL(nfs_initiate_commit); 1406 1407/* 1408 * Set up the argument/result storage required for the RPC call. 1409 */ |
1406void nfs_init_commit(struct nfs_write_data *data, | 1410void nfs_init_commit(struct nfs_commit_data *data, |
1407 struct list_head *head, 1408 struct pnfs_layout_segment *lseg) 1409{ 1410 struct nfs_page *first = nfs_list_entry(head->next); 1411 struct inode *inode = first->wb_context->dentry->d_inode; 1412 1413 /* Set up the RPC argument and reply structs 1414 * NB: take care not to mess about with data->commit et al. */ --- 4 unchanged lines hidden (view full) --- 1419 data->cred = first->wb_context->cred; 1420 data->lseg = lseg; /* reference transferred */ 1421 data->mds_ops = &nfs_commit_ops; 1422 1423 data->args.fh = NFS_FH(data->inode); 1424 /* Note: we always request a commit of the entire inode */ 1425 data->args.offset = 0; 1426 data->args.count = 0; | 1411 struct list_head *head, 1412 struct pnfs_layout_segment *lseg) 1413{ 1414 struct nfs_page *first = nfs_list_entry(head->next); 1415 struct inode *inode = first->wb_context->dentry->d_inode; 1416 1417 /* Set up the RPC argument and reply structs 1418 * NB: take care not to mess about with data->commit et al. */ --- 4 unchanged lines hidden (view full) --- 1423 data->cred = first->wb_context->cred; 1424 data->lseg = lseg; /* reference transferred */ 1425 data->mds_ops = &nfs_commit_ops; 1426 1427 data->args.fh = NFS_FH(data->inode); 1428 /* Note: we always request a commit of the entire inode */ 1429 data->args.offset = 0; 1430 data->args.count = 0; |
1427 data->args.context = get_nfs_open_context(first->wb_context); 1428 data->res.count = 0; | 1431 data->context = get_nfs_open_context(first->wb_context); |
1429 data->res.fattr = &data->fattr; 1430 data->res.verf = &data->verf; 1431 nfs_fattr_init(&data->fattr); 1432} 1433EXPORT_SYMBOL_GPL(nfs_init_commit); 1434 1435void nfs_retry_commit(struct list_head *page_list, 1436 struct pnfs_layout_segment *lseg) --- 13 unchanged lines hidden (view full) --- 1450EXPORT_SYMBOL_GPL(nfs_retry_commit); 1451 1452/* 1453 * Commit dirty pages 1454 */ 1455static int 1456nfs_commit_list(struct inode *inode, struct list_head *head, int how) 1457{ | 1432 data->res.fattr = &data->fattr; 1433 data->res.verf = &data->verf; 1434 nfs_fattr_init(&data->fattr); 1435} 1436EXPORT_SYMBOL_GPL(nfs_init_commit); 1437 1438void nfs_retry_commit(struct list_head *page_list, 1439 struct pnfs_layout_segment *lseg) --- 13 unchanged lines hidden (view full) --- 1453EXPORT_SYMBOL_GPL(nfs_retry_commit); 1454 1455/* 1456 * Commit dirty pages 1457 */ 1458static int 1459nfs_commit_list(struct inode *inode, struct list_head *head, int how) 1460{ |
1458 struct nfs_write_data *data; | 1461 struct nfs_commit_data *data; |
1459 1460 data = nfs_commitdata_alloc(); 1461 1462 if (!data) 1463 goto out_bad; 1464 1465 /* Set up the argument struct */ 1466 nfs_init_commit(data, head, NULL); | 1462 1463 data = nfs_commitdata_alloc(); 1464 1465 if (!data) 1466 goto out_bad; 1467 1468 /* Set up the argument struct */ 1469 nfs_init_commit(data, head, NULL); |
1467 return nfs_initiate_commit(data, NFS_CLIENT(inode), data->mds_ops, how); | 1470 return nfs_initiate_commit(NFS_CLIENT(inode), data, data->mds_ops, how); |
1468 out_bad: 1469 nfs_retry_commit(head, NULL); 1470 nfs_commit_clear_lock(NFS_I(inode)); 1471 return -ENOMEM; 1472} 1473 1474/* 1475 * COMMIT call returned 1476 */ 1477static void nfs_commit_done(struct rpc_task *task, void *calldata) 1478{ | 1471 out_bad: 1472 nfs_retry_commit(head, NULL); 1473 nfs_commit_clear_lock(NFS_I(inode)); 1474 return -ENOMEM; 1475} 1476 1477/* 1478 * COMMIT call returned 1479 */ 1480static void nfs_commit_done(struct rpc_task *task, void *calldata) 1481{ |
1479 struct nfs_write_data *data = calldata; | 1482 struct nfs_commit_data *data = calldata; |
1480 1481 dprintk("NFS: %5u nfs_commit_done (status %d)\n", 1482 task->tk_pid, task->tk_status); 1483 1484 /* Call the NFS version-specific code */ 1485 NFS_PROTO(data->inode)->commit_done(task, data); 1486} 1487 | 1483 1484 dprintk("NFS: %5u nfs_commit_done (status %d)\n", 1485 task->tk_pid, task->tk_status); 1486 1487 /* Call the NFS version-specific code */ 1488 NFS_PROTO(data->inode)->commit_done(task, data); 1489} 1490 |
1488void nfs_commit_release_pages(struct nfs_write_data *data) | 1491void nfs_commit_release_pages(struct nfs_commit_data *data) |
1489{ 1490 struct nfs_page *req; 1491 int status = data->task.tk_status; 1492 1493 while (!list_empty(&data->pages)) { 1494 req = nfs_list_entry(data->pages.next); 1495 nfs_list_remove_request(req); 1496 nfs_clear_page_commit(req->wb_page); --- 24 unchanged lines hidden (view full) --- 1521 next: 1522 nfs_unlock_request(req); 1523 } 1524} 1525EXPORT_SYMBOL_GPL(nfs_commit_release_pages); 1526 1527static void nfs_commit_release(void *calldata) 1528{ | 1492{ 1493 struct nfs_page *req; 1494 int status = data->task.tk_status; 1495 1496 while (!list_empty(&data->pages)) { 1497 req = nfs_list_entry(data->pages.next); 1498 nfs_list_remove_request(req); 1499 nfs_clear_page_commit(req->wb_page); --- 24 unchanged lines hidden (view full) --- 1524 next: 1525 nfs_unlock_request(req); 1526 } 1527} 1528EXPORT_SYMBOL_GPL(nfs_commit_release_pages); 1529 1530static void nfs_commit_release(void *calldata) 1531{ |
1529 struct nfs_write_data *data = calldata; | 1532 struct nfs_commit_data *data = calldata; |
1530 1531 nfs_commit_release_pages(data); 1532 nfs_commit_clear_lock(NFS_I(data->inode)); 1533 nfs_commitdata_release(calldata); 1534} 1535 1536static const struct rpc_call_ops nfs_commit_ops = { | 1533 1534 nfs_commit_release_pages(data); 1535 nfs_commit_clear_lock(NFS_I(data->inode)); 1536 nfs_commitdata_release(calldata); 1537} 1538 1539static const struct rpc_call_ops nfs_commit_ops = { |
1537 .rpc_call_prepare = nfs_write_prepare, | 1540 .rpc_call_prepare = nfs_commit_prepare, |
1538 .rpc_call_done = nfs_commit_done, 1539 .rpc_release = nfs_commit_release, 1540}; 1541 1542int nfs_commit_inode(struct inode *inode, int how) 1543{ 1544 LIST_HEAD(head); 1545 int may_wait = how & FLUSH_SYNC; --- 202 unchanged lines hidden (view full) --- 1748 if (nfs_wdata_cachep == NULL) 1749 return -ENOMEM; 1750 1751 nfs_wdata_mempool = mempool_create_slab_pool(MIN_POOL_WRITE, 1752 nfs_wdata_cachep); 1753 if (nfs_wdata_mempool == NULL) 1754 return -ENOMEM; 1755 | 1541 .rpc_call_done = nfs_commit_done, 1542 .rpc_release = nfs_commit_release, 1543}; 1544 1545int nfs_commit_inode(struct inode *inode, int how) 1546{ 1547 LIST_HEAD(head); 1548 int may_wait = how & FLUSH_SYNC; --- 202 unchanged lines hidden (view full) --- 1751 if (nfs_wdata_cachep == NULL) 1752 return -ENOMEM; 1753 1754 nfs_wdata_mempool = mempool_create_slab_pool(MIN_POOL_WRITE, 1755 nfs_wdata_cachep); 1756 if (nfs_wdata_mempool == NULL) 1757 return -ENOMEM; 1758 |
1759 nfs_cdata_cachep = kmem_cache_create("nfs_commit_data", 1760 sizeof(struct nfs_commit_data), 1761 0, SLAB_HWCACHE_ALIGN, 1762 NULL); 1763 if (nfs_cdata_cachep == NULL) 1764 return -ENOMEM; 1765 |
|
1756 nfs_commit_mempool = mempool_create_slab_pool(MIN_POOL_COMMIT, 1757 nfs_wdata_cachep); 1758 if (nfs_commit_mempool == NULL) 1759 return -ENOMEM; 1760 1761 /* 1762 * NFS congestion size, scale with available memory. 1763 * --- 27 unchanged lines hidden --- | 1766 nfs_commit_mempool = mempool_create_slab_pool(MIN_POOL_COMMIT, 1767 nfs_wdata_cachep); 1768 if (nfs_commit_mempool == NULL) 1769 return -ENOMEM; 1770 1771 /* 1772 * NFS congestion size, scale with available memory. 1773 * --- 27 unchanged lines hidden --- |