Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

nfs: fold nfs_page_group_lock_subrequests into nfs_lock_and_join_requests

Fold nfs_page_group_lock_subrequests into nfs_lock_and_join_requests to
prepare for future changes to this code, and move the helpers to write.c
as well.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Sagi Grimberg <sagi@grimberg.me>
Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>

authored by

Christoph Hellwig and committed by
Anna Schumaker
25edbcac c3f22357

+64 -81
-77
fs/nfs/pagelist.c
··· 188 188 EXPORT_SYMBOL_GPL(nfs_async_iocounter_wait); 189 189 190 190 /* 191 - * nfs_unroll_locks - unlock all newly locked reqs and wait on @req 192 - * @head: head request of page group, must be holding head lock 193 - * @req: request that couldn't lock and needs to wait on the req bit lock 194 - * 195 - * This is a helper function for nfs_lock_and_join_requests 196 - * returns 0 on success, < 0 on error. 197 - */ 198 - static void 199 - nfs_unroll_locks(struct nfs_page *head, struct nfs_page *req) 200 - { 201 - struct nfs_page *tmp; 202 - 203 - /* relinquish all the locks successfully grabbed this run */ 204 - for (tmp = head->wb_this_page ; tmp != req; tmp = tmp->wb_this_page) { 205 - if (!kref_read(&tmp->wb_kref)) 206 - continue; 207 - nfs_unlock_and_release_request(tmp); 208 - } 209 - } 210 - 211 - /* 212 - * nfs_page_group_lock_subreq - try to lock a subrequest 213 - * @head: head request of page group 214 - * @subreq: request to lock 215 - * 216 - * This is a helper function for nfs_lock_and_join_requests which 217 - * must be called with the head request and page group both locked. 218 - * On error, it returns with the page group unlocked. 219 - */ 220 - static int 221 - nfs_page_group_lock_subreq(struct nfs_page *head, struct nfs_page *subreq) 222 - { 223 - int ret; 224 - 225 - if (!kref_get_unless_zero(&subreq->wb_kref)) 226 - return 0; 227 - while (!nfs_lock_request(subreq)) { 228 - nfs_page_group_unlock(head); 229 - ret = nfs_wait_on_request(subreq); 230 - if (!ret) 231 - ret = nfs_page_group_lock(head); 232 - if (ret < 0) { 233 - nfs_unroll_locks(head, subreq); 234 - nfs_release_request(subreq); 235 - return ret; 236 - } 237 - } 238 - return 0; 239 - } 240 - 241 - /* 242 - * nfs_page_group_lock_subrequests - try to lock the subrequests 243 - * @head: head request of page group 244 - * 245 - * This is a helper function for nfs_lock_and_join_requests which 246 - * must be called with the head request locked. 247 - */ 248 - int nfs_page_group_lock_subrequests(struct nfs_page *head) 249 - { 250 - struct nfs_page *subreq; 251 - int ret; 252 - 253 - ret = nfs_page_group_lock(head); 254 - if (ret < 0) 255 - return ret; 256 - /* lock each request in the page group */ 257 - for (subreq = head->wb_this_page; subreq != head; 258 - subreq = subreq->wb_this_page) { 259 - ret = nfs_page_group_lock_subreq(head, subreq); 260 - if (ret < 0) 261 - return ret; 262 - } 263 - nfs_page_group_unlock(head); 264 - return 0; 265 - } 266 - 267 - /* 268 191 * nfs_page_set_headlock - set the request PG_HEADLOCK 269 192 * @req: request that is to be locked 270 193 *
+64 -3
fs/nfs/write.c
··· 479 479 } 480 480 481 481 /* 482 + * nfs_unroll_locks - unlock all newly locked reqs and wait on @req 483 + * @head: head request of page group, must be holding head lock 484 + * @req: request that couldn't lock and needs to wait on the req bit lock 485 + * 486 + * This is a helper function for nfs_lock_and_join_requests 487 + * returns 0 on success, < 0 on error. 488 + */ 489 + static void 490 + nfs_unroll_locks(struct nfs_page *head, struct nfs_page *req) 491 + { 492 + struct nfs_page *tmp; 493 + 494 + /* relinquish all the locks successfully grabbed this run */ 495 + for (tmp = head->wb_this_page ; tmp != req; tmp = tmp->wb_this_page) { 496 + if (!kref_read(&tmp->wb_kref)) 497 + continue; 498 + nfs_unlock_and_release_request(tmp); 499 + } 500 + } 501 + 502 + /* 503 + * nfs_page_group_lock_subreq - try to lock a subrequest 504 + * @head: head request of page group 505 + * @subreq: request to lock 506 + * 507 + * This is a helper function for nfs_lock_and_join_requests which 508 + * must be called with the head request and page group both locked. 509 + * On error, it returns with the page group unlocked. 510 + */ 511 + static int 512 + nfs_page_group_lock_subreq(struct nfs_page *head, struct nfs_page *subreq) 513 + { 514 + int ret; 515 + 516 + if (!kref_get_unless_zero(&subreq->wb_kref)) 517 + return 0; 518 + while (!nfs_lock_request(subreq)) { 519 + nfs_page_group_unlock(head); 520 + ret = nfs_wait_on_request(subreq); 521 + if (!ret) 522 + ret = nfs_page_group_lock(head); 523 + if (ret < 0) { 524 + nfs_unroll_locks(head, subreq); 525 + nfs_release_request(subreq); 526 + return ret; 527 + } 528 + } 529 + return 0; 530 + } 531 + 532 + /* 482 533 * nfs_lock_and_join_requests - join all subreqs to the head req 483 534 * @folio: the folio used to lookup the "page group" of nfs_page structures 484 535 * ··· 547 496 static struct nfs_page *nfs_lock_and_join_requests(struct folio *folio) 548 497 { 549 498 struct inode *inode = folio->mapping->host; 550 - struct nfs_page *head; 499 + struct nfs_page *head, *subreq; 551 500 struct nfs_commit_info cinfo; 552 501 int ret; 553 502 ··· 577 526 if (ret < 0) 578 527 goto out_unlock; 579 528 580 - /* lock each request in the page group */ 581 - ret = nfs_page_group_lock_subrequests(head); 529 + ret = nfs_page_group_lock(head); 582 530 if (ret < 0) 583 531 goto out_unlock; 532 + 533 + /* lock each request in the page group */ 534 + for (subreq = head->wb_this_page; 535 + subreq != head; 536 + subreq = subreq->wb_this_page) { 537 + ret = nfs_page_group_lock_subreq(head, subreq); 538 + if (ret < 0) 539 + goto out_unlock; 540 + } 541 + 542 + nfs_page_group_unlock(head); 584 543 585 544 nfs_init_cinfo_from_inode(&cinfo, inode); 586 545 nfs_join_page_group(head, &cinfo, inode);
-1
include/linux/nfs_page.h
··· 155 155 extern int nfs_wait_on_request(struct nfs_page *); 156 156 extern void nfs_unlock_request(struct nfs_page *req); 157 157 extern void nfs_unlock_and_release_request(struct nfs_page *); 158 - extern int nfs_page_group_lock_subrequests(struct nfs_page *head); 159 158 extern void nfs_join_page_group(struct nfs_page *head, 160 159 struct nfs_commit_info *cinfo, 161 160 struct inode *inode);