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

Configure Feed

Select the types of activity you want to include in your feed.

init: refactor mount_root

Provide stubs for all the lower level mount helpers, and just switch
on ROOT_DEV in the main function.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Link: https://lore.kernel.org/r/20230531125535.676098-8-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Christoph Hellwig and committed by
Jens Axboe
a6a41d39 e3102722

+56 -48
+56 -48
init/do_mounts.c
··· 453 453 #define NFSROOT_TIMEOUT_MAX 30 454 454 #define NFSROOT_RETRY_MAX 5 455 455 456 - static int __init mount_nfs_root(void) 456 + static void __init mount_nfs_root(void) 457 457 { 458 458 char *root_dev, *root_data; 459 459 unsigned int timeout; 460 - int try, err; 460 + int try; 461 461 462 - err = nfs_root_data(&root_dev, &root_data); 463 - if (err != 0) 464 - return 0; 462 + if (nfs_root_data(&root_dev, &root_data)) 463 + goto fail; 465 464 466 465 /* 467 466 * The server or network may not be ready, so try several ··· 469 470 */ 470 471 timeout = NFSROOT_TIMEOUT_MIN; 471 472 for (try = 1; ; try++) { 472 - err = do_mount_root(root_dev, "nfs", 473 - root_mountflags, root_data); 474 - if (err == 0) 475 - return 1; 473 + if (!do_mount_root(root_dev, "nfs", root_mountflags, root_data)) 474 + return; 476 475 if (try > NFSROOT_RETRY_MAX) 477 476 break; 478 477 ··· 480 483 if (timeout > NFSROOT_TIMEOUT_MAX) 481 484 timeout = NFSROOT_TIMEOUT_MAX; 482 485 } 483 - return 0; 486 + fail: 487 + pr_err("VFS: Unable to mount root fs via NFS.\n"); 484 488 } 485 - #endif 489 + #else 490 + static inline void mount_nfs_root(void) 491 + { 492 + } 493 + #endif /* CONFIG_ROOT_NFS */ 486 494 487 495 #ifdef CONFIG_CIFS_ROOT 488 496 ··· 497 495 #define CIFSROOT_TIMEOUT_MAX 30 498 496 #define CIFSROOT_RETRY_MAX 5 499 497 500 - static int __init mount_cifs_root(void) 498 + static void __init mount_cifs_root(void) 501 499 { 502 500 char *root_dev, *root_data; 503 501 unsigned int timeout; 504 - int try, err; 502 + int try; 505 503 506 - err = cifs_root_data(&root_dev, &root_data); 507 - if (err != 0) 508 - return 0; 504 + if (cifs_root_data(&root_dev, &root_data)) 505 + goto fail; 509 506 510 507 timeout = CIFSROOT_TIMEOUT_MIN; 511 508 for (try = 1; ; try++) { 512 - err = do_mount_root(root_dev, "cifs", root_mountflags, 513 - root_data); 514 - if (err == 0) 515 - return 1; 509 + if (!do_mount_root(root_dev, "cifs", root_mountflags, 510 + root_data)) 511 + return; 516 512 if (try > CIFSROOT_RETRY_MAX) 517 513 break; 518 514 ··· 519 519 if (timeout > CIFSROOT_TIMEOUT_MAX) 520 520 timeout = CIFSROOT_TIMEOUT_MAX; 521 521 } 522 - return 0; 522 + fail: 523 + pr_err("VFS: Unable to mount root fs via SMB.\n"); 523 524 } 524 - #endif 525 + #else 526 + static inline void mount_cifs_root(void) 527 + { 528 + } 529 + #endif /* CONFIG_CIFS_ROOT */ 525 530 526 531 static bool __init fs_is_nodev(char *fstype) 527 532 { ··· 568 563 return err; 569 564 } 570 565 566 + #ifdef CONFIG_BLOCK 567 + static void __init mount_block_root(void) 568 + { 569 + int err = create_dev("/dev/root", ROOT_DEV); 570 + 571 + if (err < 0) 572 + pr_emerg("Failed to create /dev/root: %d\n", err); 573 + mount_root_generic("/dev/root", root_mountflags); 574 + } 575 + #else 576 + static inline void mount_block_root(void) 577 + { 578 + } 579 + #endif /* CONFIG_BLOCK */ 580 + 571 581 void __init mount_root(void) 572 582 { 573 - #ifdef CONFIG_ROOT_NFS 574 - if (ROOT_DEV == Root_NFS) { 575 - if (!mount_nfs_root()) 576 - printk(KERN_ERR "VFS: Unable to mount root fs via NFS.\n"); 577 - return; 583 + switch (ROOT_DEV) { 584 + case Root_NFS: 585 + mount_nfs_root(); 586 + break; 587 + case Root_CIFS: 588 + mount_cifs_root(); 589 + break; 590 + case 0: 591 + if (root_device_name && root_fs_names && mount_nodev_root() == 0) 592 + break; 593 + fallthrough; 594 + default: 595 + mount_block_root(); 596 + break; 578 597 } 579 - #endif 580 - #ifdef CONFIG_CIFS_ROOT 581 - if (ROOT_DEV == Root_CIFS) { 582 - if (!mount_cifs_root()) 583 - printk(KERN_ERR "VFS: Unable to mount root fs via SMB.\n"); 584 - return; 585 - } 586 - #endif 587 - if (ROOT_DEV == 0 && root_device_name && root_fs_names) { 588 - if (mount_nodev_root() == 0) 589 - return; 590 - } 591 - #ifdef CONFIG_BLOCK 592 - { 593 - int err = create_dev("/dev/root", ROOT_DEV); 594 - 595 - if (err < 0) 596 - pr_emerg("Failed to create /dev/root: %d\n", err); 597 - mount_root_generic("/dev/root", root_mountflags); 598 - } 599 - #endif 600 598 } 601 599 602 600 /*