Fri Apr 17 09:33:37 2020 UTC ()
align buffers used for I/O to DEV_BSIZE so it's executed more optimally
when run for xbd(4) device


(jdolecek)
diff -r1.128 -r1.129 src/sbin/newfs/mkfs.c
diff -r1.115 -r1.116 src/sbin/newfs/newfs.c

cvs diff -r1.128 -r1.129 src/sbin/newfs/mkfs.c (expand / switch to unified diff)

--- src/sbin/newfs/mkfs.c 2017/02/08 16:11:40 1.128
+++ src/sbin/newfs/mkfs.c 2020/04/17 09:33:37 1.129
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: mkfs.c,v 1.128 2017/02/08 16:11:40 rin Exp $ */ 1/* $NetBSD: mkfs.c,v 1.129 2020/04/17 09:33:37 jdolecek Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1980, 1989, 1993 4 * Copyright (c) 1980, 1989, 1993
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -63,27 +63,27 @@ @@ -63,27 +63,27 @@
63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 63 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 64 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 65 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 66 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 67 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 * SUCH DAMAGE. 68 * SUCH DAMAGE.
69 */ 69 */
70 70
71#include <sys/cdefs.h> 71#include <sys/cdefs.h>
72#ifndef lint 72#ifndef lint
73#if 0 73#if 0
74static char sccsid[] = "@(#)mkfs.c 8.11 (Berkeley) 5/3/95"; 74static char sccsid[] = "@(#)mkfs.c 8.11 (Berkeley) 5/3/95";
75#else 75#else
76__RCSID("$NetBSD: mkfs.c,v 1.128 2017/02/08 16:11:40 rin Exp $"); 76__RCSID("$NetBSD: mkfs.c,v 1.129 2020/04/17 09:33:37 jdolecek Exp $");
77#endif 77#endif
78#endif /* not lint */ 78#endif /* not lint */
79 79
80#include <sys/param.h> 80#include <sys/param.h>
81#include <sys/mman.h> 81#include <sys/mman.h>
82#include <sys/time.h> 82#include <sys/time.h>
83#include <sys/resource.h> 83#include <sys/resource.h>
84#include <ufs/ufs/dinode.h> 84#include <ufs/ufs/dinode.h>
85#include <ufs/ufs/dir.h> 85#include <ufs/ufs/dir.h>
86#include <ufs/ufs/ufs_bswap.h> 86#include <ufs/ufs/ufs_bswap.h>
87#include <ufs/ufs/quota2.h> 87#include <ufs/ufs/quota2.h>
88#include <ufs/ffs/fs.h> 88#include <ufs/ffs/fs.h>
89#include <ufs/ffs/ffs_extern.h> 89#include <ufs/ffs/ffs_extern.h>
@@ -190,30 +190,32 @@ mkfs(const char *fsys, int fi, int fo, @@ -190,30 +190,32 @@ mkfs(const char *fsys, int fi, int fo,
190 long long sizepb; 190 long long sizepb;
191 int len, col, delta, fld_width, max_cols; 191 int len, col, delta, fld_width, max_cols;
192 struct winsize winsize; 192 struct winsize winsize;
193 193
194#ifndef STANDALONE 194#ifndef STANDALONE
195 gettimeofday(&tv, NULL); 195 gettimeofday(&tv, NULL);
196#endif 196#endif
197#ifdef MFS 197#ifdef MFS
198 if (mfs && !Nflag) { 198 if (mfs && !Nflag) {
199 if ((membase = mkfs_malloc(fssize * sectorsize)) == NULL) 199 if ((membase = mkfs_malloc(fssize * sectorsize)) == NULL)
200 exit(12); 200 exit(12);
201 } 201 }
202#endif 202#endif
203 if ((fsun = calloc(1, sizeof(*fsun))) == NULL) 203 if ((fsun = aligned_alloc(DEV_BSIZE, sizeof(*fsun))) == NULL)
204 exit(12); 204 exit(12);
205 if ((cgun = calloc(1, sizeof(*cgun))) == NULL) 205 memset(fsun, 0, sizeof(*fsun));
 206 if ((cgun = aligned_alloc(DEV_BSIZE, sizeof(*cgun))) == NULL)
206 exit(12); 207 exit(12);
 208 memset(cgun, 0, sizeof(*cgun));
207 209
208 fsi = fi; 210 fsi = fi;
209 fso = fo; 211 fso = fo;
210 if (Oflag == 0) { 212 if (Oflag == 0) {
211 sblock.fs_old_inodefmt = FS_42INODEFMT; 213 sblock.fs_old_inodefmt = FS_42INODEFMT;
212 sblock.fs_maxsymlinklen = 0; 214 sblock.fs_maxsymlinklen = 0;
213 sblock.fs_old_flags = 0; 215 sblock.fs_old_flags = 0;
214 } else { 216 } else {
215 sblock.fs_old_inodefmt = FS_44INODEFMT; 217 sblock.fs_old_inodefmt = FS_44INODEFMT;
216 sblock.fs_maxsymlinklen = (Oflag == 1 ? UFS1_MAXSYMLINKLEN : 218 sblock.fs_maxsymlinklen = (Oflag == 1 ? UFS1_MAXSYMLINKLEN :
217 UFS2_MAXSYMLINKLEN); 219 UFS2_MAXSYMLINKLEN);
218 sblock.fs_old_flags = FS_FLAGS_UPDATED; 220 sblock.fs_old_flags = FS_FLAGS_UPDATED;
219 if (isappleufs) 221 if (isappleufs)
@@ -623,27 +625,27 @@ mkfs(const char *fsys, int fi, int fo, @@ -623,27 +625,27 @@ mkfs(const char *fsys, int fi, int fo,
623 sblkoff += SBLOCKSIZE; 625 sblkoff += SBLOCKSIZE;
624 for (sz = SBLOCKSIZE; sz <= 0x10000; sz <<= 1) 626 for (sz = SBLOCKSIZE; sz <= 0x10000; sz <<= 1)
625 zap_old_sblock(roundup(sblkoff, sz)); 627 zap_old_sblock(roundup(sblkoff, sz));
626 } 628 }
627 /* 629 /*
628 * Also zap possible Ext2fs magic leftover to prevent 630 * Also zap possible Ext2fs magic leftover to prevent
629 * kernel vfs_mountroot() and bootloaders from mis-recognizing 631 * kernel vfs_mountroot() and bootloaders from mis-recognizing
630 * this file system as Ext2fs. 632 * this file system as Ext2fs.
631 */ 633 */
632 zap_old_sblock(EXT2FS_SBOFF); 634 zap_old_sblock(EXT2FS_SBOFF);
633 635
634#ifndef NO_APPLE_UFS 636#ifndef NO_APPLE_UFS
635 if (isappleufs) { 637 if (isappleufs) {
636 struct appleufslabel appleufs; 638 struct appleufslabel appleufs __aligned(DEV_BSIZE);
637 ffs_appleufs_set(&appleufs, appleufs_volname, 639 ffs_appleufs_set(&appleufs, appleufs_volname,
638 tv.tv_sec, 0); 640 tv.tv_sec, 0);
639 wtfs(APPLEUFS_LABEL_OFFSET/sectorsize, 641 wtfs(APPLEUFS_LABEL_OFFSET/sectorsize,
640 APPLEUFS_LABEL_SIZE, &appleufs); 642 APPLEUFS_LABEL_SIZE, &appleufs);
641 } else if (APPLEUFS_LABEL_SIZE % sectorsize == 0) { 643 } else if (APPLEUFS_LABEL_SIZE % sectorsize == 0) {
642 struct appleufslabel appleufs; 644 struct appleufslabel appleufs;
643 /* Look for & zap any existing valid apple ufs labels */ 645 /* Look for & zap any existing valid apple ufs labels */
644 rdfs(APPLEUFS_LABEL_OFFSET/sectorsize, 646 rdfs(APPLEUFS_LABEL_OFFSET/sectorsize,
645 APPLEUFS_LABEL_SIZE, &appleufs); 647 APPLEUFS_LABEL_SIZE, &appleufs);
646 if (ffs_appleufs_validate(fsys, &appleufs, NULL) == 0) { 648 if (ffs_appleufs_validate(fsys, &appleufs, NULL) == 0) {
647 memset(&appleufs, 0, sizeof(appleufs)); 649 memset(&appleufs, 0, sizeof(appleufs));
648 wtfs(APPLEUFS_LABEL_OFFSET/sectorsize, 650 wtfs(APPLEUFS_LABEL_OFFSET/sectorsize,
649 APPLEUFS_LABEL_SIZE, &appleufs); 651 APPLEUFS_LABEL_SIZE, &appleufs);
@@ -1024,27 +1026,27 @@ struct direct lost_found_dir[] = { @@ -1024,27 +1026,27 @@ struct direct lost_found_dir[] = {
1024struct odirect olost_found_dir[] = { 1026struct odirect olost_found_dir[] = {
1025 { LOSTFOUNDINO, sizeof(struct direct), 1, "." }, 1027 { LOSTFOUNDINO, sizeof(struct direct), 1, "." },
1026 { UFS_ROOTINO, sizeof(struct direct), 2, ".." }, 1028 { UFS_ROOTINO, sizeof(struct direct), 2, ".." },
1027 { 0, DIRBLKSIZ, 0, 0 }, 1029 { 0, DIRBLKSIZ, 0, 0 },
1028}; 1030};
1029#endif 1031#endif
1030 1032
1031static void copy_dir(struct direct *, struct direct *); 1033static void copy_dir(struct direct *, struct direct *);
1032 1034
1033int 1035int
1034fsinit(const struct timeval *tv, mode_t mfsmode, uid_t mfsuid, gid_t mfsgid) 1036fsinit(const struct timeval *tv, mode_t mfsmode, uid_t mfsuid, gid_t mfsgid)
1035{ 1037{
1036 union dinode node; 1038 union dinode node;
1037 union Buffer buf; 1039 union Buffer buf __aligned(DEV_BSIZE);
1038 int i; 1040 int i;
1039 int qblocks = 0; 1041 int qblocks = 0;
1040 int qinos = 0; 1042 int qinos = 0;
1041 uint8_t q2h_hash_shift; 1043 uint8_t q2h_hash_shift;
1042 uint16_t q2h_hash_mask; 1044 uint16_t q2h_hash_mask;
1043#ifdef LOSTDIR 1045#ifdef LOSTDIR
1044 int dirblksiz = DIRBLKSIZ; 1046 int dirblksiz = DIRBLKSIZ;
1045 if (isappleufs) 1047 if (isappleufs)
1046 dirblksiz = APPLEUFS_DIRBLKSIZ; 1048 dirblksiz = APPLEUFS_DIRBLKSIZ;
1047 int nextino = LOSTFOUNDINO+1; 1049 int nextino = LOSTFOUNDINO+1;
1048#else 1050#else
1049 int nextino = UFS_ROOTINO+1; 1051 int nextino = UFS_ROOTINO+1;
1050#endif 1052#endif
@@ -1574,27 +1576,27 @@ ilog2(int val) @@ -1574,27 +1576,27 @@ ilog2(int val)
1574{ 1576{
1575 u_int n; 1577 u_int n;
1576 1578
1577 for (n = 0; n < sizeof(n) * CHAR_BIT; n++) 1579 for (n = 0; n < sizeof(n) * CHAR_BIT; n++)
1578 if (1 << n == val) 1580 if (1 << n == val)
1579 return (n); 1581 return (n);
1580 errx(1, "ilog2: %d is not a power of 2", val); 1582 errx(1, "ilog2: %d is not a power of 2", val);
1581} 1583}
1582 1584
1583static void 1585static void
1584zap_old_sblock(int sblkoff) 1586zap_old_sblock(int sblkoff)
1585{ 1587{
1586 static int cg0_data; 1588 static int cg0_data;
1587 uint32_t oldfs[SBLOCKSIZE / 4]; 1589 uint32_t oldfs[SBLOCKSIZE / 4] __aligned(DEV_BSIZE);
1588 static const struct fsm { 1590 static const struct fsm {
1589 uint32_t offset; 1591 uint32_t offset;
1590 uint32_t magic; 1592 uint32_t magic;
1591 uint32_t mask; 1593 uint32_t mask;
1592 } fs_magics[] = { 1594 } fs_magics[] = {
1593 {offsetof(struct fs, fs_magic)/4, FS_UFS1_MAGIC, ~0u}, 1595 {offsetof(struct fs, fs_magic)/4, FS_UFS1_MAGIC, ~0u},
1594 {offsetof(struct fs, fs_magic)/4, FS_UFS2_MAGIC, ~0u}, 1596 {offsetof(struct fs, fs_magic)/4, FS_UFS2_MAGIC, ~0u},
1595 {0, 0x70162, ~0u}, /* LFS_MAGIC */ 1597 {0, 0x70162, ~0u}, /* LFS_MAGIC */
1596 {14, 0xef53, 0xffff}, /* EXT2FS (little) */ 1598 {14, 0xef53, 0xffff}, /* EXT2FS (little) */
1597 {14, 0xef530000, 0xffff0000}, /* EXT2FS (big) */ 1599 {14, 0xef530000, 0xffff0000}, /* EXT2FS (big) */
1598 {.offset = ~0u}, 1600 {.offset = ~0u},
1599 }; 1601 };
1600 const struct fsm *fsm; 1602 const struct fsm *fsm;

cvs diff -r1.115 -r1.116 src/sbin/newfs/newfs.c (expand / switch to unified diff)

--- src/sbin/newfs/newfs.c 2017/02/08 16:11:40 1.115
+++ src/sbin/newfs/newfs.c 2020/04/17 09:33:37 1.116
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: newfs.c,v 1.115 2017/02/08 16:11:40 rin Exp $ */ 1/* $NetBSD: newfs.c,v 1.116 2020/04/17 09:33:37 jdolecek Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1983, 1989, 1993, 1994 4 * Copyright (c) 1983, 1989, 1993, 1994
5 * The Regents of the University of California. All rights reserved. 5 * The Regents of the University of California. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -68,27 +68,27 @@ @@ -68,27 +68,27 @@
68 * SUCH DAMAGE. 68 * SUCH DAMAGE.
69 */ 69 */
70 70
71#include <sys/cdefs.h> 71#include <sys/cdefs.h>
72#ifndef lint 72#ifndef lint
73__COPYRIGHT("@(#) Copyright (c) 1983, 1989, 1993, 1994\ 73__COPYRIGHT("@(#) Copyright (c) 1983, 1989, 1993, 1994\
74 The Regents of the University of California. All rights reserved."); 74 The Regents of the University of California. All rights reserved.");
75#endif /* not lint */ 75#endif /* not lint */
76 76
77#ifndef lint 77#ifndef lint
78#if 0 78#if 0
79static char sccsid[] = "@(#)newfs.c 8.13 (Berkeley) 5/1/95"; 79static char sccsid[] = "@(#)newfs.c 8.13 (Berkeley) 5/1/95";
80#else 80#else
81__RCSID("$NetBSD: newfs.c,v 1.115 2017/02/08 16:11:40 rin Exp $"); 81__RCSID("$NetBSD: newfs.c,v 1.116 2020/04/17 09:33:37 jdolecek Exp $");
82#endif 82#endif
83#endif /* not lint */ 83#endif /* not lint */
84 84
85/* 85/*
86 * newfs: friendly front end to mkfs 86 * newfs: friendly front end to mkfs
87 */ 87 */
88#include <sys/param.h> 88#include <sys/param.h>
89#include <sys/ioctl.h> 89#include <sys/ioctl.h>
90#include <sys/disklabel.h> 90#include <sys/disklabel.h>
91#include <sys/disk.h> 91#include <sys/disk.h>
92#include <sys/file.h> 92#include <sys/file.h>
93#include <sys/mount.h> 93#include <sys/mount.h>
94#include <sys/sysctl.h> 94#include <sys/sysctl.h>
@@ -609,29 +609,30 @@ main(int argc, char *argv[]) @@ -609,29 +609,30 @@ main(int argc, char *argv[])
609 609
610 if (Zflag && fso != -1) { /* pre-zero (and de-sparce) the file */ 610 if (Zflag && fso != -1) { /* pre-zero (and de-sparce) the file */
611 char *buf; 611 char *buf;
612 int bufsize, i; 612 int bufsize, i;
613 off_t bufrem; 613 off_t bufrem;
614 struct statvfs sfs; 614 struct statvfs sfs;
615 615
616 if (fstatvfs(fso, &sfs) == -1) { 616 if (fstatvfs(fso, &sfs) == -1) {
617 warn("can't fstatvfs `%s'", special); 617 warn("can't fstatvfs `%s'", special);
618 bufsize = 8192; 618 bufsize = 8192;
619 } else 619 } else
620 bufsize = sfs.f_iosize; 620 bufsize = sfs.f_iosize;
621 621
622 if ((buf = calloc(1, bufsize)) == NULL) 622 if ((buf = aligned_alloc(DEV_BSIZE, bufsize)) == NULL)
623 err(1, "can't malloc buffer of %d", 623 err(1, "can't malloc buffer of %d",
624 bufsize); 624 bufsize);
 625 memset(buf, 0, bufsize);
625 bufrem = fssize * sectorsize; 626 bufrem = fssize * sectorsize;
626 if (verbosity > 0) 627 if (verbosity > 0)
627 printf( "Creating file system image in `%s', " 628 printf( "Creating file system image in `%s', "
628 "size %lld bytes, in %d byte chunks.\n", 629 "size %lld bytes, in %d byte chunks.\n",
629 special, (long long)bufrem, bufsize); 630 special, (long long)bufrem, bufsize);
630 while (bufrem > 0) { 631 while (bufrem > 0) {
631 i = write(fso, buf, MIN(bufsize, bufrem)); 632 i = write(fso, buf, MIN(bufsize, bufrem));
632 if (i == -1) 633 if (i == -1)
633 err(1, "writing image"); 634 err(1, "writing image");
634 bufrem -= i; 635 bufrem -= i;
635 } 636 }
636 free(buf); 637 free(buf);
637 } 638 }