aboutsummaryrefslogtreecommitdiff
path: root/util-linux/mount.c
diff options
context:
space:
mode:
authorJames Byrne <james.byrne@origamienergy.com>2019-07-02 11:35:03 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2019-07-02 11:35:03 +0200
commit6937487be73cd4563b876413277a295a5fe2f32c (patch)
treef16cc9999a7c827891e6ec8d99c699fc791008ee /util-linux/mount.c
parentcaecfdc20d450686cd1f7e9b5f650322f894b3c2 (diff)
downloadbusybox-w32-6937487be73cd4563b876413277a295a5fe2f32c.tar.gz
busybox-w32-6937487be73cd4563b876413277a295a5fe2f32c.tar.bz2
busybox-w32-6937487be73cd4563b876413277a295a5fe2f32c.zip
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower overhead call to bb_perror_msg() when only a string was being printed with no parameters. This saves space for some CPU architectures because it avoids the overhead of a call to a variadic function. However there has never been a simple version of bb_error_msg(), and since 2007 many new calls to bb_perror_msg() have been added that only take a single parameter and so could have been using bb_simple_perror_message(). This changeset introduces 'simple' versions of bb_info_msg(), bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and bb_herror_msg_and_die(), and replaces all calls that only take a single parameter, or use something like ("%s", arg), with calls to the corresponding 'simple' version. Since it is likely that single parameter calls to the variadic functions may be accidentally reintroduced in the future a new debugging config option WARN_SIMPLE_MSG has been introduced. This uses some macro magic which will cause any such calls to generate a warning, but this is turned off by default to avoid use of the unpleasant macros in normal circumstances. This is a large changeset due to the number of calls that have been replaced. The only files that contain changes other than simple substitution of function calls are libbb.h, libbb/herror_msg.c, libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c, networking/udhcp/common.h and util-linux/mdev.c additonal macros have been added for logging so that single parameter and multiple parameter logging variants exist. The amount of space saved varies considerably by architecture, and was found to be as follows (for 'defconfig' using GCC 7.4): Arm: -92 bytes MIPS: -52 bytes PPC: -1836 bytes x86_64: -938 bytes Note that for the MIPS architecture only an exception had to be made disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h) because it made these files larger on MIPS. Signed-off-by: James Byrne <james.byrne@origamienergy.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux/mount.c')
-rw-r--r--util-linux/mount.c40
1 files changed, 20 insertions, 20 deletions
diff --git a/util-linux/mount.c b/util-linux/mount.c
index e6bad7c2c..84c85c057 100644
--- a/util-linux/mount.c
+++ b/util-linux/mount.c
@@ -483,7 +483,7 @@ static void FAST_FUNC update_mtab_entry_on_move(const struct mntent *mp)
483 483
484 mountTable = setmntent(bb_path_mtab_file, "r"); 484 mountTable = setmntent(bb_path_mtab_file, "r");
485 if (!mountTable) { 485 if (!mountTable) {
486 bb_perror_msg(bb_path_mtab_file); 486 bb_simple_perror_msg(bb_path_mtab_file);
487 return; 487 return;
488 } 488 }
489 489
@@ -511,7 +511,7 @@ static void FAST_FUNC update_mtab_entry_on_move(const struct mntent *mp)
511 } 511 }
512 endmntent(mountTable); 512 endmntent(mountTable);
513 } else if (errno != EROFS) 513 } else if (errno != EROFS)
514 bb_perror_msg(bb_path_mtab_file); 514 bb_simple_perror_msg(bb_path_mtab_file);
515 515
516 if (ENABLE_FEATURE_CLEAN_UP) { 516 if (ENABLE_FEATURE_CLEAN_UP) {
517 for (i = 0; i < count; i++) { 517 for (i = 0; i < count; i++) {
@@ -739,7 +739,7 @@ static int mount_it_now(struct mntent *mp, unsigned long vfsflags, char *filtero
739 // Abort entirely if permission denied. 739 // Abort entirely if permission denied.
740 740
741 if (rc && errno == EPERM) 741 if (rc && errno == EPERM)
742 bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); 742 bb_simple_error_msg_and_die(bb_msg_perm_denied_are_you_root);
743 743
744 // If the mount was successful, and we're maintaining an old-style 744 // If the mount was successful, and we're maintaining an old-style
745 // mtab file by hand, add the new entry to it now. 745 // mtab file by hand, add the new entry to it now.
@@ -751,7 +751,7 @@ static int mount_it_now(struct mntent *mp, unsigned long vfsflags, char *filtero
751 int i; 751 int i;
752 752
753 if (!mountTable) { 753 if (!mountTable) {
754 bb_perror_msg(bb_path_mtab_file); 754 bb_simple_perror_msg(bb_path_mtab_file);
755 goto ret; 755 goto ret;
756 } 756 }
757 757
@@ -1288,18 +1288,18 @@ static NOINLINE int nfsmount(struct mntent *mp, unsigned long vfsflags, char *fi
1288 s = strchr(hostname, ','); 1288 s = strchr(hostname, ',');
1289 if (s) { 1289 if (s) {
1290 *s = '\0'; 1290 *s = '\0';
1291 bb_error_msg("warning: multiple hostnames not supported"); 1291 bb_simple_error_msg("warning: multiple hostnames not supported");
1292 } 1292 }
1293 1293
1294 server_addr.sin_family = AF_INET; 1294 server_addr.sin_family = AF_INET;
1295 if (!inet_aton(hostname, &server_addr.sin_addr)) { 1295 if (!inet_aton(hostname, &server_addr.sin_addr)) {
1296 hp = gethostbyname(hostname); 1296 hp = gethostbyname(hostname);
1297 if (hp == NULL) { 1297 if (hp == NULL) {
1298 bb_herror_msg("%s", hostname); 1298 bb_simple_herror_msg(hostname);
1299 goto fail; 1299 goto fail;
1300 } 1300 }
1301 if (hp->h_length != (int)sizeof(struct in_addr)) { 1301 if (hp->h_length != (int)sizeof(struct in_addr)) {
1302 bb_error_msg_and_die("only IPv4 is supported"); 1302 bb_simple_error_msg_and_die("only IPv4 is supported");
1303 } 1303 }
1304 memcpy(&server_addr.sin_addr, hp->h_addr_list[0], sizeof(struct in_addr)); 1304 memcpy(&server_addr.sin_addr, hp->h_addr_list[0], sizeof(struct in_addr));
1305 } 1305 }
@@ -1389,7 +1389,7 @@ static NOINLINE int nfsmount(struct mntent *mp, unsigned long vfsflags, char *fi
1389 else if (is_prefixed_with(opteq, "udp")) 1389 else if (is_prefixed_with(opteq, "udp"))
1390 tcp = 0; 1390 tcp = 0;
1391 else 1391 else
1392 bb_error_msg("warning: unrecognized proto= option"); 1392 bb_simple_error_msg("warning: unrecognized proto= option");
1393 continue; 1393 continue;
1394 case 20: // "addr" - ignore 1394 case 20: // "addr" - ignore
1395 continue; 1395 continue;
@@ -1522,7 +1522,7 @@ static NOINLINE int nfsmount(struct mntent *mp, unsigned long vfsflags, char *fi
1522 if (nfs_mount_version >= 3) 1522 if (nfs_mount_version >= 3)
1523 nolock = !val; 1523 nolock = !val;
1524 else 1524 else
1525 bb_error_msg("warning: option nolock is not supported"); 1525 bb_simple_error_msg("warning: option nolock is not supported");
1526 break; 1526 break;
1527 case 11: //rdirplus 1527 case 11: //rdirplus
1528 nordirplus = !val; 1528 nordirplus = !val;
@@ -1590,11 +1590,11 @@ static NOINLINE int nfsmount(struct mntent *mp, unsigned long vfsflags, char *fi
1590 } else { 1590 } else {
1591 hp = gethostbyname(mounthost); 1591 hp = gethostbyname(mounthost);
1592 if (hp == NULL) { 1592 if (hp == NULL) {
1593 bb_herror_msg("%s", mounthost); 1593 bb_simple_herror_msg(mounthost);
1594 goto fail; 1594 goto fail;
1595 } 1595 }
1596 if (hp->h_length != (int)sizeof(struct in_addr)) { 1596 if (hp->h_length != (int)sizeof(struct in_addr)) {
1597 bb_error_msg_and_die("only IPv4 is supported"); 1597 bb_simple_error_msg_and_die("only IPv4 is supported");
1598 } 1598 }
1599 mount_server_addr.sin_family = AF_INET; 1599 mount_server_addr.sin_family = AF_INET;
1600 memcpy(&mount_server_addr.sin_addr, hp->h_addr_list[0], sizeof(struct in_addr)); 1600 memcpy(&mount_server_addr.sin_addr, hp->h_addr_list[0], sizeof(struct in_addr));
@@ -1767,18 +1767,18 @@ static NOINLINE int nfsmount(struct mntent *mp, unsigned long vfsflags, char *fi
1767 /* Create nfs socket for kernel */ 1767 /* Create nfs socket for kernel */
1768 if (tcp) { 1768 if (tcp) {
1769 if (nfs_mount_version < 3) { 1769 if (nfs_mount_version < 3) {
1770 bb_error_msg("NFS over TCP is not supported"); 1770 bb_simple_error_msg("NFS over TCP is not supported");
1771 goto fail; 1771 goto fail;
1772 } 1772 }
1773 fsock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); 1773 fsock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
1774 } else 1774 } else
1775 fsock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); 1775 fsock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
1776 if (fsock < 0) { 1776 if (fsock < 0) {
1777 bb_perror_msg("nfs socket"); 1777 bb_simple_perror_msg("nfs socket");
1778 goto fail; 1778 goto fail;
1779 } 1779 }
1780 if (bindresvport(fsock, 0) < 0) { 1780 if (bindresvport(fsock, 0) < 0) {
1781 bb_perror_msg("nfs bindresvport"); 1781 bb_simple_perror_msg("nfs bindresvport");
1782 goto fail; 1782 goto fail;
1783 } 1783 }
1784 if (port == 0) { 1784 if (port == 0) {
@@ -2047,9 +2047,9 @@ static int singlemount(struct mntent *mp, int ignore_busy)
2047 ); 2047 );
2048 if (loopfd < 0) { 2048 if (loopfd < 0) {
2049 if (errno == EPERM || errno == EACCES) 2049 if (errno == EPERM || errno == EACCES)
2050 bb_error_msg(bb_msg_perm_denied_are_you_root); 2050 bb_simple_error_msg(bb_msg_perm_denied_are_you_root);
2051 else 2051 else
2052 bb_perror_msg("can't setup loop device"); 2052 bb_simple_perror_msg("can't setup loop device");
2053 return errno; 2053 return errno;
2054 } 2054 }
2055 2055
@@ -2255,7 +2255,7 @@ int mount_main(int argc UNUSED_PARAM, char **argv)
2255 // argument when we get it. 2255 // argument when we get it.
2256 if (argv[1]) { 2256 if (argv[1]) {
2257 if (nonroot) 2257 if (nonroot)
2258 bb_error_msg_and_die(bb_msg_you_must_be_root); 2258 bb_simple_error_msg_and_die(bb_msg_you_must_be_root);
2259 mtpair->mnt_fsname = argv[0]; 2259 mtpair->mnt_fsname = argv[0];
2260 mtpair->mnt_dir = argv[1]; 2260 mtpair->mnt_dir = argv[1];
2261 mtpair->mnt_type = fstype; 2261 mtpair->mnt_type = fstype;
@@ -2272,7 +2272,7 @@ int mount_main(int argc UNUSED_PARAM, char **argv)
2272 2272
2273 cmdopt_flags = parse_mount_options(cmdopts, NULL); 2273 cmdopt_flags = parse_mount_options(cmdopts, NULL);
2274 if (nonroot && (cmdopt_flags & ~MS_SILENT)) // Non-root users cannot specify flags 2274 if (nonroot && (cmdopt_flags & ~MS_SILENT)) // Non-root users cannot specify flags
2275 bb_error_msg_and_die(bb_msg_you_must_be_root); 2275 bb_simple_error_msg_and_die(bb_msg_you_must_be_root);
2276 2276
2277 // If we have a shared subtree flag, don't worry about fstab or mtab. 2277 // If we have a shared subtree flag, don't worry about fstab or mtab.
2278 if (ENABLE_FEATURE_MOUNT_FLAGS 2278 if (ENABLE_FEATURE_MOUNT_FLAGS
@@ -2337,7 +2337,7 @@ int mount_main(int argc UNUSED_PARAM, char **argv)
2337 // No, mount -a won't mount anything, 2337 // No, mount -a won't mount anything,
2338 // even user mounts, for mere humans 2338 // even user mounts, for mere humans
2339 if (nonroot) 2339 if (nonroot)
2340 bb_error_msg_and_die(bb_msg_you_must_be_root); 2340 bb_simple_error_msg_and_die(bb_msg_you_must_be_root);
2341 2341
2342 // Does type match? (NULL matches always) 2342 // Does type match? (NULL matches always)
2343 if (!fstype_matches(mtcur->mnt_type, fstype)) 2343 if (!fstype_matches(mtcur->mnt_type, fstype))
@@ -2417,7 +2417,7 @@ int mount_main(int argc UNUSED_PARAM, char **argv)
2417 // fstab must have "users" or "user" 2417 // fstab must have "users" or "user"
2418 l = parse_mount_options(mtcur->mnt_opts, NULL); 2418 l = parse_mount_options(mtcur->mnt_opts, NULL);
2419 if (!(l & MOUNT_USERS)) 2419 if (!(l & MOUNT_USERS))
2420 bb_error_msg_and_die(bb_msg_you_must_be_root); 2420 bb_simple_error_msg_and_die(bb_msg_you_must_be_root);
2421 } 2421 }
2422 2422
2423 //util-linux-2.12 does not do this check. 2423 //util-linux-2.12 does not do this check.