diff --git a/sbin/fsck_msdosfs/boot.c b/sbin/fsck_msdosfs/boot.c index ae786e7..b777d08 100644 --- a/sbin/fsck_msdosfs/boot.c +++ b/sbin/fsck_msdosfs/boot.c @@ -10,13 +10,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Martin Husemann - * and Wolfgang Solfrank. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES @@ -40,7 +33,6 @@ static const char rcsid[] = #include #include -#include #include #include @@ -48,16 +40,15 @@ static const char rcsid[] = #include "fsutil.h" int -readboot(dosfs, boot) - int dosfs; - struct bootblock *boot; +readboot(int dosfs, struct bootblock *boot) { u_char block[DOSBOOTBLOCKSIZE]; u_char fsinfo[2 * DOSBOOTBLOCKSIZE]; u_char backup[DOSBOOTBLOCKSIZE]; int ret = FSOK; + int i; - if (read(dosfs, block, sizeof block) < sizeof block) { + if ((size_t)read(dosfs, block, sizeof block) != sizeof block) { perror("could not read boot block"); return FSFATAL; } @@ -71,22 +62,22 @@ readboot(dosfs, boot) boot->ValidFat = -1; /* decode bios parameter block */ - boot->BytesPerSec = block[11] + (block[12] << 8); - boot->SecPerClust = block[13]; - boot->ResSectors = block[14] + (block[15] << 8); - boot->FATs = block[16]; - boot->RootDirEnts = block[17] + (block[18] << 8); - boot->Sectors = block[19] + (block[20] << 8); - boot->Media = block[21]; - boot->FATsmall = block[22] + (block[23] << 8); + boot->bpbBytesPerSec = block[11] + (block[12] << 8); + boot->bpbSecPerClust = block[13]; + boot->bpbResSectors = block[14] + (block[15] << 8); + boot->bpbFATs = block[16]; + boot->bpbRootDirEnts = block[17] + (block[18] << 8); + boot->bpbSectors = block[19] + (block[20] << 8); + boot->bpbMedia = block[21]; + boot->bpbFATsmall = block[22] + (block[23] << 8); boot->SecPerTrack = block[24] + (block[25] << 8); - boot->Heads = block[26] + (block[27] << 8); - boot->HiddenSecs = block[28] + (block[29] << 8) + (block[30] << 16) + (block[31] << 24); - boot->HugeSectors = block[32] + (block[33] << 8) + (block[34] << 16) + (block[35] << 24); + boot->bpbHeads = block[26] + (block[27] << 8); + boot->bpbHiddenSecs = block[28] + (block[29] << 8) + (block[30] << 16) + (block[31] << 24); + boot->bpbHugeSectors = block[32] + (block[33] << 8) + (block[34] << 16) + (block[35] << 24); - boot->FATsecs = boot->FATsmall; + boot->FATsecs = boot->bpbFATsmall; - if (!boot->RootDirEnts) + if (!boot->bpbRootDirEnts) boot->flags |= FAT32; if (boot->flags & FAT32) { boot->FATsecs = block[36] + (block[37] << 8) @@ -101,13 +92,13 @@ readboot(dosfs, boot) block[43], block[42]); return FSFATAL; } - boot->RootCl = block[44] + (block[45] << 8) + boot->bpbRootClust = block[44] + (block[45] << 8) + (block[46] << 16) + (block[47] << 24); - boot->FSInfo = block[48] + (block[49] << 8); - boot->Backup = block[50] + (block[51] << 8); + boot->bpbFSInfo = block[48] + (block[49] << 8); + boot->bpbBackup = block[50] + (block[51] << 8); - if (lseek(dosfs, boot->FSInfo * boot->BytesPerSec, SEEK_SET) - != boot->FSInfo * boot->BytesPerSec + if (lseek(dosfs, boot->bpbFSInfo * boot->bpbBytesPerSec, SEEK_SET) + != boot->bpbFSInfo * boot->bpbBytesPerSec || read(dosfs, fsinfo, sizeof fsinfo) != sizeof fsinfo) { perror("could not read fsinfo block"); @@ -133,18 +124,18 @@ readboot(dosfs, boot) fsinfo[0x3fc] = fsinfo[0x3fd] = 0; fsinfo[0x3fe] = 0x55; fsinfo[0x3ff] = 0xaa; - if (lseek(dosfs, boot->FSInfo * boot->BytesPerSec, SEEK_SET) - != boot->FSInfo * boot->BytesPerSec + if (lseek(dosfs, boot->bpbFSInfo * boot->bpbBytesPerSec, SEEK_SET) + != boot->bpbFSInfo * boot->bpbBytesPerSec || write(dosfs, fsinfo, sizeof fsinfo) != sizeof fsinfo) { - perror("Unable to write FSInfo"); + perror("Unable to write bpbFSInfo"); return FSFATAL; } ret = FSBOOTMOD; } else - boot->FSInfo = 0; + boot->bpbFSInfo = 0; } - if (boot->FSInfo) { + if (boot->bpbFSInfo) { boot->FSFree = fsinfo[0x1e8] + (fsinfo[0x1e9] << 8) + (fsinfo[0x1ea] << 16) + (fsinfo[0x1eb] << 24); @@ -153,44 +144,54 @@ readboot(dosfs, boot) + (fsinfo[0x1ef] << 24); } - if (lseek(dosfs, boot->Backup * boot->BytesPerSec, SEEK_SET) - != boot->Backup * boot->BytesPerSec + if (lseek(dosfs, boot->bpbBackup * boot->bpbBytesPerSec, SEEK_SET) + != boot->bpbBackup * boot->bpbBytesPerSec || read(dosfs, backup, sizeof backup) != sizeof backup) { perror("could not read backup bootblock"); return FSFATAL; } backup[65] = block[65]; /* XXX */ if (memcmp(block + 11, backup + 11, 79)) { - /* Correct? XXX */ - pfatal("backup doesn't compare to primary bootblock"); - if (alwaysno) - pfatal("\n"); - else - return FSFATAL; + /* + * XXX We require a reference that explains + * that these bytes need to match, or should + * drop the check. gdt@NetBSD has observed + * filesystems that work fine under Windows XP + * and NetBSD that do not match, so the + * requirement is suspect. For now, just + * print out useful information and continue. + */ + pfatal("backup (block %d) mismatch with primary bootblock:\n", + boot->bpbBackup); + for (i = 11; i < 11 + 90; i++) { + if (block[i] != backup[i]) + pfatal("\ti=%d\tprimary 0x%02x\tbackup 0x%02x\n", + i, block[i], backup[i]); + } } - /* Check backup FSInfo? XXX */ + /* Check backup bpbFSInfo? XXX */ } - boot->ClusterOffset = (boot->RootDirEnts * 32 + boot->BytesPerSec - 1) - / boot->BytesPerSec - + boot->ResSectors - + boot->FATs * boot->FATsecs - - CLUST_FIRST * boot->SecPerClust; + boot->ClusterOffset = (boot->bpbRootDirEnts * 32 + boot->bpbBytesPerSec - 1) + / boot->bpbBytesPerSec + + boot->bpbResSectors + + boot->bpbFATs * boot->FATsecs + - CLUST_FIRST * boot->bpbSecPerClust; - if (boot->BytesPerSec % DOSBOOTBLOCKSIZE != 0) { - pfatal("Invalid sector size: %u", boot->BytesPerSec); + if (boot->bpbBytesPerSec % DOSBOOTBLOCKSIZE != 0) { + pfatal("Invalid sector size: %u", boot->bpbBytesPerSec); return FSFATAL; } - if (boot->SecPerClust == 0) { - pfatal("Invalid cluster size: %u", boot->SecPerClust); + if (boot->bpbSecPerClust == 0) { + pfatal("Invalid cluster size: %u", boot->bpbSecPerClust); return FSFATAL; } - if (boot->Sectors) { - boot->HugeSectors = 0; - boot->NumSectors = boot->Sectors; + if (boot->bpbSectors) { + boot->bpbHugeSectors = 0; + boot->NumSectors = boot->bpbSectors; } else - boot->NumSectors = boot->HugeSectors; - boot->NumClusters = (boot->NumSectors - boot->ClusterOffset) / boot->SecPerClust; + boot->NumSectors = boot->bpbHugeSectors; + boot->NumClusters = (boot->NumSectors - boot->ClusterOffset) / boot->bpbSecPerClust; if (boot->flags&FAT32) boot->ClustMask = CLUST32_MASK; @@ -206,13 +207,13 @@ readboot(dosfs, boot) switch (boot->ClustMask) { case CLUST32_MASK: - boot->NumFatEntries = (boot->FATsecs * boot->BytesPerSec) / 4; + boot->NumFatEntries = (boot->FATsecs * boot->bpbBytesPerSec) / 4; break; case CLUST16_MASK: - boot->NumFatEntries = (boot->FATsecs * boot->BytesPerSec) / 2; + boot->NumFatEntries = (boot->FATsecs * boot->bpbBytesPerSec) / 2; break; default: - boot->NumFatEntries = (boot->FATsecs * boot->BytesPerSec * 2) / 3; + boot->NumFatEntries = (boot->FATsecs * boot->bpbBytesPerSec * 2) / 3; break; } @@ -221,7 +222,7 @@ readboot(dosfs, boot) boot->NumClusters, boot->FATsecs); return FSFATAL; } - boot->ClusterSize = boot->BytesPerSec * boot->SecPerClust; + boot->ClusterSize = boot->bpbBytesPerSec * boot->bpbSecPerClust; boot->NumFiles = 1; boot->NumFree = 0; @@ -230,14 +231,12 @@ readboot(dosfs, boot) } int -writefsinfo(dosfs, boot) - int dosfs; - struct bootblock *boot; +writefsinfo(int dosfs, struct bootblock *boot) { u_char fsinfo[2 * DOSBOOTBLOCKSIZE]; - if (lseek(dosfs, boot->FSInfo * boot->BytesPerSec, SEEK_SET) - != boot->FSInfo * boot->BytesPerSec + if (lseek(dosfs, boot->bpbFSInfo * boot->bpbBytesPerSec, SEEK_SET) + != boot->bpbFSInfo * boot->bpbBytesPerSec || read(dosfs, fsinfo, sizeof fsinfo) != sizeof fsinfo) { perror("could not read fsinfo block"); return FSFATAL; @@ -250,11 +249,11 @@ writefsinfo(dosfs, boot) fsinfo[0x1ed] = (u_char)(boot->FSNext >> 8); fsinfo[0x1ee] = (u_char)(boot->FSNext >> 16); fsinfo[0x1ef] = (u_char)(boot->FSNext >> 24); - if (lseek(dosfs, boot->FSInfo * boot->BytesPerSec, SEEK_SET) - != boot->FSInfo * boot->BytesPerSec + if (lseek(dosfs, boot->bpbFSInfo * boot->bpbBytesPerSec, SEEK_SET) + != boot->bpbFSInfo * boot->bpbBytesPerSec || write(dosfs, fsinfo, sizeof fsinfo) != sizeof fsinfo) { - perror("Unable to write FSInfo"); + perror("Unable to write bpbFSInfo"); return FSFATAL; } /* diff --git a/sbin/fsck_msdosfs/check.c b/sbin/fsck_msdosfs/check.c index 48ae5ca..a762f8a 100644 --- a/sbin/fsck_msdosfs/check.c +++ b/sbin/fsck_msdosfs/check.c @@ -10,13 +10,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Martin Husemann - * and Wolfgang Solfrank. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES @@ -40,7 +33,6 @@ static const char rcsid[] = #include #include -#include #include #include #include @@ -54,7 +46,8 @@ checkfilesys(const char *fname) int dosfs; struct bootblock boot; struct fatEntry *fat = NULL; - int i, finish_dosdirsection=0; + int finish_dosdirsection=0; + u_int i; int mod = 0; int ret = 8; @@ -105,7 +98,7 @@ checkfilesys(const char *fname) } if (boot.ValidFat < 0) - for (i = 1; i < (int)boot.FATs; i++) { + for (i = 1; i < (int)boot.bpbFATs; i++) { struct fatEntry *currentFat; mod |= readfat(dosfs, &boot, i, ¤tFat); diff --git a/sbin/fsck_msdosfs/dir.c b/sbin/fsck_msdosfs/dir.c index b87a916..181fa37 100644 --- a/sbin/fsck_msdosfs/dir.c +++ b/sbin/fsck_msdosfs/dir.c @@ -12,13 +12,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Martin Husemann - * and Wolfgang Solfrank. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES @@ -44,7 +37,6 @@ static const char rcsid[] = #include #include #include -#include #include #include @@ -227,26 +219,38 @@ resetDosDirSection(struct bootblock *boot, struct fatEntry *fat) cl_t cl; int ret = FSOK; - b1 = boot->RootDirEnts * 32; - b2 = boot->SecPerClust * boot->BytesPerSec; + b1 = boot->bpbRootDirEnts * 32; + b2 = boot->bpbSecPerClust * boot->bpbBytesPerSec; - if (!(buffer = malloc(b1 > b2 ? b1 : b2)) - || !(delbuf = malloc(b2)) - || !(rootDir = newDosDirEntry())) { - perror("No space for directory"); + if ((buffer = malloc( b1 > b2 ? b1 : b2)) == NULL) { + perror("No space for directory buffer"); return FSFATAL; } + + if ((delbuf = malloc(b2)) == NULL) { + free(buffer); + perror("No space for directory delbuf"); + return FSFATAL; + } + + if ((rootDir = newDosDirEntry()) == NULL) { + free(buffer); + free(delbuf); + perror("No space for directory entry"); + return FSFATAL; + } + memset(rootDir, 0, sizeof *rootDir); if (boot->flags & FAT32) { - if (boot->RootCl < CLUST_FIRST || boot->RootCl >= boot->NumClusters) { + if (boot->bpbRootClust < CLUST_FIRST || boot->bpbRootClust >= boot->NumClusters) { pfatal("Root directory starts with cluster out of range(%u)", - boot->RootCl); + boot->bpbRootClust); return FSFATAL; } - cl = fat[boot->RootCl].next; + cl = fat[boot->bpbRootClust].next; if (cl < CLUST_FIRST || (cl >= CLUST_RSRVD && cl< CLUST_EOFS) - || fat[boot->RootCl].head != boot->RootCl) { + || fat[boot->bpbRootClust].head != boot->bpbRootClust) { if (cl == CLUST_FREE) pwarn("Root directory starts with free cluster\n"); else if (cl >= CLUST_RSRVD) @@ -257,14 +261,14 @@ resetDosDirSection(struct bootblock *boot, struct fatEntry *fat) return FSFATAL; } if (ask(1, "Fix")) { - fat[boot->RootCl].next = CLUST_FREE; + fat[boot->bpbRootClust].next = CLUST_FREE; ret = FSFATMOD; } else ret = FSFATAL; } - fat[boot->RootCl].flags |= FAT_USED; - rootDir->head = boot->RootCl; + fat[boot->bpbRootClust].flags |= FAT_USED; + rootDir->head = boot->bpbRootClust; } return ret; @@ -309,7 +313,7 @@ delete(int f, struct bootblock *boot, struct fatEntry *fat, cl_t startcl, { u_char *s, *e; off_t off; - int clsz = boot->SecPerClust * boot->BytesPerSec; + int clsz = boot->bpbSecPerClust * boot->bpbBytesPerSec; s = delbuf + startoff; e = delbuf + clsz; @@ -319,8 +323,8 @@ delete(int f, struct bootblock *boot, struct fatEntry *fat, cl_t startcl, break; e = delbuf + endoff; } - off = startcl * boot->SecPerClust + boot->ClusterOffset; - off *= boot->BytesPerSec; + off = startcl * boot->bpbSecPerClust + boot->ClusterOffset; + off *= boot->bpbBytesPerSec; if (lseek(f, off, SEEK_SET) != off || read(f, delbuf, clsz) != clsz) { perror("Unable to read directory"); @@ -367,7 +371,8 @@ removede(int f, struct bootblock *boot, struct fatEntry *fat, u_char *start, return FSFATAL; start = buffer; } - if (endcl == curcl) + /* startcl is < CLUST_FIRST for !fat32 root */ + if ((endcl == curcl) || (startcl < CLUST_FIRST)) for (; start < end; start += 32) *start = SLOT_DELETED; return FSDIRMOD; @@ -385,7 +390,7 @@ checksize(struct bootblock *boot, struct fatEntry *fat, u_char *p, /* * Check size on ordinary files */ - int32_t physicalSize; + u_int32_t physicalSize; if (dir->head == CLUST_FREE) physicalSize = 0; @@ -456,14 +461,14 @@ readDosDirSection(int f, struct bootblock *boot, struct fatEntry *fat, vallfn = invlfn = empty = NULL; do { if (!(boot->flags & FAT32) && !dir->parent) { - last = boot->RootDirEnts * 32; - off = boot->ResSectors + boot->FATs * boot->FATsecs; + last = boot->bpbRootDirEnts * 32; + off = boot->bpbResSectors + boot->bpbFATs * boot->FATsecs; } else { - last = boot->SecPerClust * boot->BytesPerSec; - off = cl * boot->SecPerClust + boot->ClusterOffset; + last = boot->bpbSecPerClust * boot->bpbBytesPerSec; + off = cl * boot->bpbSecPerClust + boot->ClusterOffset; } - off *= boot->BytesPerSec; + off *= boot->bpbBytesPerSec; if (lseek(f, off, SEEK_SET) != off || read(f, buffer, last) != last) { perror("Unable to read directory"); @@ -644,7 +649,8 @@ readDosDirSection(int f, struct bootblock *boot, struct fatEntry *fat, dirent.head |= (p[20] << 16) | (p[21] << 24); dirent.size = p[28] | (p[29] << 8) | (p[30] << 16) | (p[31] << 24); if (vallfn) { - strcpy(dirent.lname, longName); + strlcpy(dirent.lname, longName, + sizeof(dirent.lname)); longName[0] = '\0'; shortSum = -1; } @@ -832,6 +838,10 @@ readDosDirSection(int f, struct bootblock *boot, struct fatEntry *fat, } boot->NumFiles++; } + + if (!(boot->flags & FAT32) && !dir->parent) + break; + if (mod & THISMOD) { last *= 32; if (lseek(f, off, SEEK_SET) != off @@ -847,6 +857,19 @@ readDosDirSection(int f, struct bootblock *boot, struct fatEntry *fat, invlfn ? invlfn : vallfn, p, invlfn ? invcl : valcl, -1, 0, fullpath(dir), 1); + + /* The root directory of non fat32 filesystems is in a special + * area and may have been modified above without being written out. + */ + if ((mod & FSDIRMOD) && !(boot->flags & FAT32) && !dir->parent) { + last *= 32; + if (lseek(f, off, SEEK_SET) != off + || write(f, buffer, last) != last) { + perror("Unable to write directory"); + return FSFATAL; + } + mod &= ~THISMOD; + } return mod & ~THISMOD; } @@ -934,9 +957,9 @@ reconnect(int dosfs, struct bootblock *boot, struct fatEntry *fat, cl_t head) return FSERROR; } lfoff = lfcl * boot->ClusterSize - + boot->ClusterOffset * boot->BytesPerSec; + + boot->ClusterOffset * boot->bpbBytesPerSec; if (lseek(dosfs, lfoff, SEEK_SET) != lfoff - || read(dosfs, lfbuf, boot->ClusterSize) != boot->ClusterSize) { + || (size_t)read(dosfs, lfbuf, boot->ClusterSize) != boot->ClusterSize) { perror("could not read LOST.DIR"); return FSFATAL; } @@ -966,7 +989,7 @@ reconnect(int dosfs, struct bootblock *boot, struct fatEntry *fat, cl_t head) p[31] = (u_char)(d.size >> 24); fat[head].flags |= FAT_USED; if (lseek(dosfs, lfoff, SEEK_SET) != lfoff - || write(dosfs, lfbuf, boot->ClusterSize) != boot->ClusterSize) { + || (size_t)write(dosfs, lfbuf, boot->ClusterSize) != boot->ClusterSize) { perror("could not write LOST.DIR"); return FSFATAL; } diff --git a/sbin/fsck_msdosfs/dosfs.h b/sbin/fsck_msdosfs/dosfs.h index 3a5d439..bd01b24 100644 --- a/sbin/fsck_msdosfs/dosfs.h +++ b/sbin/fsck_msdosfs/dosfs.h @@ -12,13 +12,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Martin Husemann - * and Wolfgang Solfrank. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES @@ -46,21 +39,21 @@ typedef u_int32_t cl_t; /* type holding a cluster number */ * FAT boot block. */ struct bootblock { - u_int BytesPerSec; /* bytes per sector */ - u_int SecPerClust; /* sectors per cluster */ - u_int ResSectors; /* number of reserved sectors */ - u_int FATs; /* number of FATs */ - u_int RootDirEnts; /* number of root directory entries */ - u_int Media; /* media descriptor */ - u_int FATsmall; /* number of sectors per FAT */ + u_int bpbBytesPerSec; /* bytes per sector */ + u_int bpbSecPerClust; /* sectors per cluster */ + u_int bpbResSectors; /* number of reserved sectors */ + u_int bpbFATs; /* number of bpbFATs */ + u_int bpbRootDirEnts; /* number of root directory entries */ + u_int32_t bpbSectors; /* total number of sectors */ + u_int bpbMedia; /* media descriptor */ + u_int bpbFATsmall; /* number of sectors per FAT */ u_int SecPerTrack; /* sectors per track */ - u_int Heads; /* number of heads */ - u_int32_t Sectors; /* total number of sectors */ - u_int32_t HiddenSecs; /* # of hidden sectors */ - u_int32_t HugeSectors; /* # of sectors if bpbSectors == 0 */ - u_int FSInfo; /* FSInfo sector */ - u_int Backup; /* Backup of Bootblocks */ - cl_t RootCl; /* Start of Root Directory */ + u_int bpbHeads; /* number of heads */ + u_int32_t bpbHiddenSecs; /* # of hidden sectors */ + u_int32_t bpbHugeSectors; /* # of sectors if bpbbpbSectors == 0 */ + cl_t bpbRootClust; /* Start of Root Directory */ + u_int bpbFSInfo; /* FSInfo sector */ + u_int bpbBackup; /* Backup of Bootblocks */ cl_t FSFree; /* Number of free clusters acc. FSInfo */ cl_t FSNext; /* Next free cluster acc. FSInfo */ diff --git a/sbin/fsck_msdosfs/ext.h b/sbin/fsck_msdosfs/ext.h index 53127cf..a4fd19b 100644 --- a/sbin/fsck_msdosfs/ext.h +++ b/sbin/fsck_msdosfs/ext.h @@ -10,13 +10,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Martin Husemann - * and Wolfgang Solfrank. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES @@ -77,12 +70,12 @@ int checkfilesys(const char *); #define FSDIRMOD 2 /* Some directory was modified */ #define FSFATMOD 4 /* The FAT was modified */ #define FSERROR 8 /* Some unrecovered error remains */ -#define FSFATAL 16 /* Some unrecoverable error occured */ +#define FSFATAL 16 /* Some unrecoverable error occurred */ #define FSDIRTY 32 /* File system is dirty */ #define FSFIXFAT 64 /* Fix file system FAT */ /* - * read a boot block in a machine independend fashion and translate + * read a boot block in a machine independent fashion and translate * it into our struct bootblock. */ int readboot(int, struct bootblock *); @@ -96,13 +89,13 @@ int writefsinfo(int, struct bootblock *); * Read one of the FAT copies and return a pointer to the new * allocated array holding our description of it. */ -int readfat(int, struct bootblock *, int, struct fatEntry **); +int readfat(int, struct bootblock *, u_int, struct fatEntry **); /* * Check two FAT copies for consistency and merge changes into the - * first if neccessary. + * first if necessary. */ -int comparefat(struct bootblock *, struct fatEntry *, struct fatEntry *, int); +int comparefat(struct bootblock *, struct fatEntry *, struct fatEntry *, u_int); /* * Check a FAT diff --git a/sbin/fsck_msdosfs/fat.c b/sbin/fsck_msdosfs/fat.c index e509717..126c3ef 100644 --- a/sbin/fsck_msdosfs/fat.c +++ b/sbin/fsck_msdosfs/fat.c @@ -10,13 +10,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Martin Husemann - * and Wolfgang Solfrank. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES @@ -47,10 +40,10 @@ static const char rcsid[] = #include "ext.h" #include "fsutil.h" -static int checkclnum(struct bootblock *, int, cl_t, cl_t *); -static int clustdiffer(cl_t, cl_t *, cl_t *, int); +static int checkclnum(struct bootblock *, u_int, cl_t, cl_t *); +static int clustdiffer(cl_t, cl_t *, cl_t *, u_int); static int tryclear(struct bootblock *, struct fatEntry *, cl_t, cl_t *); -static int _readfat(int, struct bootblock *, int, u_char **); +static int _readfat(int, struct bootblock *, u_int, u_char **); /*- * The first 2 FAT entries contain pseudo-cluster numbers with the following @@ -80,10 +73,10 @@ checkdirty(int fs, struct bootblock *boot) if (boot->ClustMask != CLUST16_MASK && boot->ClustMask != CLUST32_MASK) return 0; - off = boot->ResSectors; - off *= boot->BytesPerSec; + off = boot->bpbResSectors; + off *= boot->bpbBytesPerSec; - buffer = malloc(boot->BytesPerSec); + buffer = malloc(boot->bpbBytesPerSec); if (buffer == NULL) { perror("No space for FAT"); return 1; @@ -94,7 +87,7 @@ checkdirty(int fs, struct bootblock *boot) goto err; } - if (read(fs, buffer, boot->BytesPerSec) != boot->BytesPerSec) { + if (read(fs, buffer, boot->bpbBytesPerSec) != boot->bpbBytesPerSec) { perror("Unable to read FAT"); goto err; } @@ -103,7 +96,7 @@ checkdirty(int fs, struct bootblock *boot) * If we don't understand the FAT, then the file system must be * assumed to be unclean. */ - if (buffer[0] != boot->Media || buffer[1] != 0xff) + if (buffer[0] != boot->bpbMedia || buffer[1] != 0xff) goto err; if (boot->ClustMask == CLUST16_MASK) { if ((buffer[2] & 0xf8) != 0xf8 || (buffer[3] & 0x3f) != 0x3f) @@ -135,7 +128,7 @@ err: * Check a cluster number for valid value */ static int -checkclnum(struct bootblock *boot, int fat, cl_t cl, cl_t *next) +checkclnum(struct bootblock *boot, u_int fat, cl_t cl, cl_t *next) { if (*next >= (CLUST_RSRVD&boot->ClustMask)) *next |= ~boot->ClustMask; @@ -166,26 +159,26 @@ checkclnum(struct bootblock *boot, int fat, cl_t cl, cl_t *next) * Read a FAT from disk. Returns 1 if successful, 0 otherwise. */ static int -_readfat(int fs, struct bootblock *boot, int no, u_char **buffer) +_readfat(int fs, struct bootblock *boot, u_int no, u_char **buffer) { off_t off; - *buffer = malloc(boot->FATsecs * boot->BytesPerSec); + *buffer = malloc(boot->FATsecs * boot->bpbBytesPerSec); if (*buffer == NULL) { perror("No space for FAT"); return 0; } - off = boot->ResSectors + no * boot->FATsecs; - off *= boot->BytesPerSec; + off = boot->bpbResSectors + no * boot->FATsecs; + off *= boot->bpbBytesPerSec; if (lseek(fs, off, SEEK_SET) != off) { perror("Unable to read FAT"); goto err; } - if (read(fs, *buffer, boot->FATsecs * boot->BytesPerSec) - != boot->FATsecs * boot->BytesPerSec) { + if ((size_t)read(fs, *buffer, boot->FATsecs * boot->bpbBytesPerSec) + != boot->FATsecs * boot->bpbBytesPerSec) { perror("Unable to read FAT"); goto err; } @@ -201,26 +194,28 @@ _readfat(int fs, struct bootblock *boot, int no, u_char **buffer) * Read a FAT and decode it into internal format */ int -readfat(int fs, struct bootblock *boot, int no, struct fatEntry **fp) +readfat(int fs, struct bootblock *boot, u_int no, struct fatEntry **fp) { struct fatEntry *fat; u_char *buffer, *p; cl_t cl; int ret = FSOK; + size_t len; boot->NumFree = boot->NumBad = 0; if (!_readfat(fs, boot, no, &buffer)) return FSFATAL; - fat = calloc(boot->NumClusters, sizeof(struct fatEntry)); + fat = malloc(len = boot->NumClusters * sizeof(struct fatEntry)); if (fat == NULL) { perror("No space for FAT"); free(buffer); return FSFATAL; } + (void)memset(fat, 0, len); - if (buffer[0] != boot->Media + if (buffer[0] != boot->bpbMedia || buffer[1] != 0xff || buffer[2] != 0xff || (boot->ClustMask == CLUST16_MASK && buffer[3] != 0xff) || (boot->ClustMask == CLUST32_MASK @@ -234,7 +229,7 @@ readfat(int fs, struct bootblock *boot, int no, struct fatEntry **fp) * file system is dirty if it doesn't reboot cleanly. * Check this special condition before errorring out. */ - if (buffer[0] == boot->Media && buffer[1] == 0xff + if (buffer[0] == boot->bpbMedia && buffer[1] == 0xff && buffer[2] == 0xff && ((boot->ClustMask == CLUST16_MASK && buffer[3] == 0x7f) || (boot->ClustMask == CLUST32_MASK @@ -311,7 +306,11 @@ readfat(int fs, struct bootblock *boot, int no, struct fatEntry **fp) } free(buffer); - *fp = fat; + if (ret & FSFATAL) { + free(fat); + *fp = NULL; + } else + *fp = fat; return ret; } @@ -331,7 +330,7 @@ rsrvdcltype(cl_t cl) } static int -clustdiffer(cl_t cl, cl_t *cp1, cl_t *cp2, int fatnum) +clustdiffer(cl_t cl, cl_t *cp1, cl_t *cp2, u_int fatnum) { if (*cp1 == CLUST_FREE || *cp1 >= CLUST_RSRVD) { if (*cp2 == CLUST_FREE || *cp2 >= CLUST_RSRVD) { @@ -346,13 +345,13 @@ clustdiffer(cl_t cl, cl_t *cp1, cl_t *cp2, int fatnum) } return FSFATAL; } - pwarn("Cluster %u is marked %s in FAT 0, %s in FAT %d\n", + pwarn("Cluster %u is marked %s in FAT 0, %s in FAT %u\n", cl, rsrvdcltype(*cp1), rsrvdcltype(*cp2), fatnum); if (ask(0, "Use FAT 0's entry")) { *cp2 = *cp1; return FSFATMOD; } - if (ask(0, "Use FAT %d's entry", fatnum)) { + if (ask(0, "Use FAT %u's entry", fatnum)) { *cp1 = *cp2; return FSFATMOD; } @@ -360,7 +359,7 @@ clustdiffer(cl_t cl, cl_t *cp1, cl_t *cp2, int fatnum) } pwarn("Cluster %u is marked %s in FAT 0, but continues with cluster %u in FAT %d\n", cl, rsrvdcltype(*cp1), *cp2, fatnum); - if (ask(0, "Use continuation from FAT %d", fatnum)) { + if (ask(0, "Use continuation from FAT %u", fatnum)) { *cp1 = *cp2; return FSFATMOD; } @@ -371,7 +370,7 @@ clustdiffer(cl_t cl, cl_t *cp1, cl_t *cp2, int fatnum) return FSFATAL; } if (*cp2 == CLUST_FREE || *cp2 >= CLUST_RSRVD) { - pwarn("Cluster %u continues with cluster %u in FAT 0, but is marked %s in FAT %d\n", + pwarn("Cluster %u continues with cluster %u in FAT 0, but is marked %s in FAT %u\n", cl, *cp1, rsrvdcltype(*cp2), fatnum); if (ask(0, "Use continuation from FAT 0")) { *cp2 = *cp1; @@ -383,13 +382,13 @@ clustdiffer(cl_t cl, cl_t *cp1, cl_t *cp2, int fatnum) } return FSERROR; } - pwarn("Cluster %u continues with cluster %u in FAT 0, but with cluster %u in FAT %d\n", + pwarn("Cluster %u continues with cluster %u in FAT 0, but with cluster %u in FAT %u\n", cl, *cp1, *cp2, fatnum); if (ask(0, "Use continuation from FAT 0")) { *cp2 = *cp1; return FSFATMOD; } - if (ask(0, "Use continuation from FAT %d", fatnum)) { + if (ask(0, "Use continuation from FAT %u", fatnum)) { *cp1 = *cp2; return FSFATMOD; } @@ -401,8 +400,8 @@ clustdiffer(cl_t cl, cl_t *cp1, cl_t *cp2, int fatnum) * into the first one. */ int -comparefat(struct bootblock *boot, struct fatEntry *first, - struct fatEntry *second, int fatnum) +comparefat(struct bootblock *boot, struct fatEntry *first, + struct fatEntry *second, u_int fatnum) { cl_t cl; int ret = FSOK; @@ -542,12 +541,12 @@ writefat(int fs, struct bootblock *boot, struct fatEntry *fat, int correct_fat) { u_char *buffer, *p; cl_t cl; - int i; - u_int32_t fatsz; + u_int i; + size_t fatsz; off_t off; int ret = FSOK; - buffer = malloc(fatsz = boot->FATsecs * boot->BytesPerSec); + buffer = malloc(fatsz = boot->FATsecs * boot->bpbBytesPerSec); if (buffer == NULL) { perror("No space for FAT"); return FSFATAL; @@ -556,7 +555,7 @@ writefat(int fs, struct bootblock *boot, struct fatEntry *fat, int correct_fat) boot->NumFree = 0; p = buffer; if (correct_fat) { - *p++ = (u_char)boot->Media; + *p++ = (u_char)boot->bpbMedia; *p++ = 0xff; *p++ = 0xff; switch (boot->ClustMask) { @@ -629,11 +628,11 @@ writefat(int fs, struct bootblock *boot, struct fatEntry *fat, int correct_fat) break; } } - for (i = 0; i < boot->FATs; i++) { - off = boot->ResSectors + i * boot->FATsecs; - off *= boot->BytesPerSec; + for (i = 0; i < boot->bpbFATs; i++) { + off = boot->bpbResSectors + i * boot->FATsecs; + off *= boot->bpbBytesPerSec; if (lseek(fs, off, SEEK_SET) != off - || write(fs, buffer, fatsz) != fatsz) { + || (size_t)write(fs, buffer, fatsz) != fatsz) { perror("Unable to write FAT"); ret = FSFATAL; /* Return immediately? XXX */ } @@ -673,7 +672,7 @@ checklost(int dosfs, struct bootblock *boot, struct fatEntry *fat) } finishlf(); - if (boot->FSInfo) { + if (boot->bpbFSInfo) { ret = 0; if (boot->FSFree != boot->NumFree) { pwarn("Free space in FSInfo block (%d) not correct (%d)\n", @@ -683,17 +682,6 @@ checklost(int dosfs, struct bootblock *boot, struct fatEntry *fat) ret = 1; } } - if (boot->NumFree && fat[boot->FSNext].next != CLUST_FREE) { - pwarn("Next free cluster in FSInfo block (%u) not free\n", - boot->FSNext); - if (ask(1, "Fix")) - for (head = CLUST_FIRST; head < boot->NumClusters; head++) - if (fat[head].next == CLUST_FREE) { - boot->FSNext = head; - ret = 1; - break; - } - } if (ret) mod |= writefsinfo(dosfs, boot); } diff --git a/sbin/fsck_msdosfs/fsck_msdosfs.8 b/sbin/fsck_msdosfs/fsck_msdosfs.8 index 3bc22b1..6099e55 100644 --- a/sbin/fsck_msdosfs/fsck_msdosfs.8 +++ b/sbin/fsck_msdosfs/fsck_msdosfs.8 @@ -11,13 +11,6 @@ .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by Martin Husemann -.\" and Wolfgang Solfrank. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES diff --git a/sbin/fsck_msdosfs/main.c b/sbin/fsck_msdosfs/main.c index c09abd5..9ec15ca 100644 --- a/sbin/fsck_msdosfs/main.c +++ b/sbin/fsck_msdosfs/main.c @@ -10,13 +10,6 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Martin Husemann - * and Wolfgang Solfrank. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES @@ -40,7 +33,6 @@ static const char rcsid[] = #include #include -#include #include #include #include diff --git a/sbin/newfs_msdos/newfs_msdos.8 b/sbin/newfs_msdos/newfs_msdos.8 index c96e5f5..1c63a74 100644 --- a/sbin/newfs_msdos/newfs_msdos.8 +++ b/sbin/newfs_msdos/newfs_msdos.8 @@ -38,14 +38,14 @@ .Op Fl B Ar boot .Op Fl C Ar create-size .Op Fl F Ar FAT-type -.Op Fl I Ar volid +.Op Fl I Ar VolumeId .Op Fl L Ar label .Op Fl O Ar OEM .Op Fl S Ar sector-size .Op Fl a Ar FAT-size .Op Fl b Ar block-size .Op Fl c Ar cluster-size -.Op Fl e Ar dirents +.Op Fl e Ar DirEnts .Op Fl f Ar format .Op Fl h Ar heads .Op Fl i Ar info @@ -103,7 +103,7 @@ If the file system supports sparse files, the space occupied on disk may be smaller than the size specified as parameter. .It Fl F Ar FAT-type FAT type (one of 12, 16, or 32). -.It Fl I Ar volid +.It Fl I Ar VolumeID Volume ID, a 32 bit number in decimal or hexadecimal (0x...) format. .It Fl L Ar label Volume label (up to 11 characters). @@ -116,7 +116,7 @@ The default is .It Fl S Ar sector-size Number of bytes per sector. Acceptable values are powers of 2 -in the range 128 through 32768. +in the range 512 through 32768. .It Fl a Ar FAT-size Number of sectors per FAT. .It Fl b Ar block-size @@ -130,7 +130,7 @@ Acceptable values are powers of 2 in the range If the block or cluster size are not specified, the code uses a cluster between 512 bytes and 32K depending on the filesystem size. -.It Fl e Ar dirents +.It Fl e Ar DirEnts Number of root directory entries (FAT12 and FAT16 only). .It Fl f Ar format Specify a standard (floppy disk) format. diff --git a/sbin/newfs_msdos/newfs_msdos.c b/sbin/newfs_msdos/newfs_msdos.c index f09578a..9061631 100644 --- a/sbin/newfs_msdos/newfs_msdos.c +++ b/sbin/newfs_msdos/newfs_msdos.c @@ -62,12 +62,12 @@ static const char rcsid[] = #define DEFBLK16 2048 /* default block size FAT16 */ #define DEFRDE 512 /* default root directory entries */ #define RESFTE 2 /* reserved FAT entries */ -#define MINCLS12 1 /* minimum FAT12 clusters */ -#define MINCLS16 0x1000 /* minimum FAT16 clusters */ -#define MINCLS32 2 /* minimum FAT32 clusters */ -#define MAXCLS12 0xfed /* maximum FAT12 clusters */ -#define MAXCLS16 0xfff5 /* maximum FAT16 clusters */ -#define MAXCLS32 0xffffff5 /* maximum FAT32 clusters */ +#define MINCLS12 1U /* minimum FAT12 clusters */ +#define MINCLS16 0x1000U /* minimum FAT16 clusters */ +#define MINCLS32 2U /* minimum FAT32 clusters */ +#define MAXCLS12 0xfedU /* maximum FAT12 clusters */ +#define MAXCLS16 0xfff5U /* maximum FAT16 clusters */ +#define MAXCLS32 0xffffff5U /* maximum FAT32 clusters */ #define mincls(fat) ((fat) == 12 ? MINCLS12 : \ (fat) == 16 ? MINCLS16 : \ @@ -96,23 +96,23 @@ static const char rcsid[] = #define argtox(arg, lo, msg) argtou(arg, lo, UINT_MAX, msg) struct bs { - u_int8_t jmp[3]; /* bootstrap entry point */ - u_int8_t oem[8]; /* OEM name and version */ + u_int8_t bsJump[3]; /* bootstrap entry point */ + u_int8_t bsOemName[8]; /* OEM name and version */ }; struct bsbpb { - u_int8_t bps[2]; /* bytes per sector */ - u_int8_t spc; /* sectors per cluster */ - u_int8_t res[2]; /* reserved sectors */ - u_int8_t nft; /* number of FATs */ - u_int8_t rde[2]; /* root directory entries */ - u_int8_t sec[2]; /* total sectors */ - u_int8_t mid; /* media descriptor */ - u_int8_t spf[2]; /* sectors per FAT */ - u_int8_t spt[2]; /* sectors per track */ - u_int8_t hds[2]; /* drive heads */ - u_int8_t hid[4]; /* hidden sectors */ - u_int8_t bsec[4]; /* big total sectors */ + u_int8_t bpbBytesPerSec[2]; /* bytes per sector */ + u_int8_t bpbSecPerClust; /* sectors per cluster */ + u_int8_t bpbResSectors[2]; /* reserved sectors */ + u_int8_t bpbFATs; /* number of FATs */ + u_int8_t bpbRootDirEnts[2]; /* root directory entries */ + u_int8_t bpbSectors[2]; /* total sectors */ + u_int8_t bpbMedia; /* media descriptor */ + u_int8_t bpbFATsecs[2]; /* sectors per FAT */ + u_int8_t bpbSecPerTrack[2]; /* sectors per track */ + u_int8_t bpbHeads[2]; /* drive heads */ + u_int8_t bpbHiddenSecs[4]; /* hidden sectors */ + u_int8_t bpbHugeSectors[4]; /* big total sectors */ }; struct bsxbpb { @@ -122,63 +122,67 @@ struct bsxbpb { u_int8_t rdcl[4]; /* root directory start cluster */ u_int8_t infs[2]; /* file system info sector */ u_int8_t bkbs[2]; /* backup boot sector */ - u_int8_t rsvd[12]; /* reserved */ + u_int8_t rsvd[12]; /* reserved */ }; struct bsx { - u_int8_t drv; /* drive number */ - u_int8_t rsvd; /* reserved */ - u_int8_t sig; /* extended boot signature */ - u_int8_t volid[4]; /* volume ID number */ - u_int8_t label[11]; /* volume label */ - u_int8_t type[8]; /* file system type */ + u_int8_t exDriveNumber; /* drive number */ + u_int8_t exReserved1; /* reserved */ + u_int8_t exBootSignature; /* extended boot signature */ + u_int8_t exVolumeID[4]; /* volume ID number */ + u_int8_t exVolumeLabel[11]; /* volume label */ + u_int8_t exFileSysType[8]; /* file system type */ }; struct de { - u_int8_t namext[11]; /* name and extension */ - u_int8_t attr; /* attributes */ + u_int8_t deName[11]; /* name and extension */ + u_int8_t deAttributes; /* attributes */ u_int8_t rsvd[10]; /* reserved */ - u_int8_t time[2]; /* creation time */ - u_int8_t date[2]; /* creation date */ - u_int8_t clus[2]; /* starting cluster */ - u_int8_t size[4]; /* size */ + u_int8_t deCTime[2]; /* creation time */ + u_int8_t deCDate[2]; /* creation date */ + u_int8_t deStartCluster[2]; /* starting cluster */ + u_int8_t deFileSize[4]; /* size */ }; struct bpb { - u_int bps; /* bytes per sector */ - u_int spc; /* sectors per cluster */ - u_int res; /* reserved sectors */ - u_int nft; /* number of FATs */ - u_int rde; /* root directory entries */ - u_int sec; /* total sectors */ - u_int mid; /* media descriptor */ - u_int spf; /* sectors per FAT */ - u_int spt; /* sectors per track */ - u_int hds; /* drive heads */ - u_int hid; /* hidden sectors */ - u_int bsec; /* big total sectors */ - u_int bspf; /* big sectors per FAT */ - u_int rdcl; /* root directory start cluster */ - u_int infs; /* file system info sector */ - u_int bkbs; /* backup boot sector */ + u_int bpbBytesPerSec; /* bytes per sector */ + u_int bpbSecPerClust; /* sectors per cluster */ + u_int bpbResSectors; /* reserved sectors */ + u_int bpbFATs; /* number of FATs */ + u_int bpbRootDirEnts; /* root directory entries */ + u_int bpbSectors; /* total sectors */ + u_int bpbMedia; /* media descriptor */ + u_int bpbFATsecs; /* sectors per FAT */ + u_int bpbSecPerTrack; /* sectors per track */ + u_int bpbHeads; /* drive heads */ + u_int bpbHiddenSecs; /* hidden sectors */ + u_int bpbHugeSectors; /* big total sectors */ + u_int bpbBigFATsecs; /* big sectors per FAT */ +/* XXX: Missing EXTFlags FSVers */ + u_int bpbRootClust; /* root directory start cluster */ + u_int bpbFSInfo; /* file system info sector */ + u_int bpbBackup; /* backup boot sector */ }; #define BPBGAP 0, 0, 0, 0, 0, 0 +#define INIT(a, b, c, d, e, f, g, h, i, j) \ + { .bpbBytesPerSec = a, .bpbSecPerClust = b, .bpbResSectors = c, .bpbFATs = d, .bpbRootDirEnts = e, \ + .bpbSectors = f, .bpbMedia = g, .bpbFATsecs = h, .bpbSecPerTrack = i, .bpbHeads = j, } static struct { const char *name; struct bpb bpb; } const stdfmt[] = { - {"160", {512, 1, 1, 2, 64, 320, 0xfe, 1, 8, 1, BPBGAP}}, - {"180", {512, 1, 1, 2, 64, 360, 0xfc, 2, 9, 1, BPBGAP}}, - {"320", {512, 2, 1, 2, 112, 640, 0xff, 1, 8, 2, BPBGAP}}, - {"360", {512, 2, 1, 2, 112, 720, 0xfd, 2, 9, 2, BPBGAP}}, - {"640", {512, 2, 1, 2, 112, 1280, 0xfb, 2, 8, 2, BPBGAP}}, - {"720", {512, 2, 1, 2, 112, 1440, 0xf9, 3, 9, 2, BPBGAP}}, - {"1200", {512, 1, 1, 2, 224, 2400, 0xf9, 7, 15, 2, BPBGAP}}, - {"1232", {1024,1, 1, 2, 192, 1232, 0xfe, 2, 8, 2, BPBGAP}}, - {"1440", {512, 1, 1, 2, 224, 2880, 0xf0, 9, 18, 2, BPBGAP}}, - {"2880", {512, 2, 1, 2, 240, 5760, 0xf0, 9, 36, 2, BPBGAP}} + {"160", INIT(512, 1, 1, 2, 64, 320, 0xfe, 1, 8, 1)}, + {"180", INIT(512, 1, 1, 2, 64, 360, 0xfc, 2, 9, 1)}, + {"320", INIT(512, 2, 1, 2, 112, 640, 0xff, 1, 8, 2)}, + {"360", INIT(512, 2, 1, 2, 112, 720, 0xfd, 2, 9, 2)}, + {"640", INIT(512, 2, 1, 2, 112, 1280, 0xfb, 2, 8, 2)}, + {"720", INIT(512, 2, 1, 2, 112, 1440, 0xf9, 3, 9, 2)}, + {"1200", INIT(512, 1, 1, 2, 224, 2400, 0xf9, 7, 15, 2)}, + {"1232", INIT(1024,1, 1, 2, 192, 1232, 0xfe, 2, 8, 2)}, + {"1440", INIT(512, 1, 1, 2, 224, 2880, 0xf0, 9, 18, 2)}, + {"2880", INIT(512, 2, 1, 2, 240, 5760, 0xf0, 9, 36, 2)} }; static const u_int8_t bootcode[] = { @@ -381,49 +385,49 @@ main(int argc, char *argv[]) memset(&bpb, 0, sizeof(bpb)); if (opt_f) { getstdfmt(opt_f, &bpb); - bpb.bsec = bpb.sec; - bpb.sec = 0; - bpb.bspf = bpb.spf; - bpb.spf = 0; + bpb.bpbHugeSectors = bpb.bpbSectors; + bpb.bpbSectors = 0; + bpb.bpbBigFATsecs = bpb.bpbFATsecs; + bpb.bpbFATsecs = 0; } if (opt_h) - bpb.hds = opt_h; + bpb.bpbHeads = opt_h; if (opt_u) - bpb.spt = opt_u; + bpb.bpbSecPerTrack = opt_u; if (opt_S) - bpb.bps = opt_S; + bpb.bpbBytesPerSec = opt_S; if (opt_s) - bpb.bsec = opt_s; + bpb.bpbHugeSectors = opt_s; if (oflag) - bpb.hid = opt_o; + bpb.bpbHiddenSecs = opt_o; if (!(opt_f || (opt_h && opt_u && opt_S && opt_s && oflag))) { off_t delta; getdiskinfo(fd, fname, dtype, oflag, &bpb); - bpb.bsec -= (opt_ofs / bpb.bps); - delta = bpb.bsec % bpb.spt; + bpb.bpbHugeSectors -= (opt_ofs / bpb.bpbBytesPerSec); + delta = bpb.bpbHugeSectors % bpb.bpbSecPerTrack; if (delta != 0) { warnx("trim %d sectors to adjust to a multiple of %d", - (int)delta, bpb.spt); - bpb.bsec -= delta; + (int)delta, bpb.bpbSecPerTrack); + bpb.bpbHugeSectors -= delta; } - if (bpb.spc == 0) { /* set defaults */ - if (bpb.bsec <= 6000) /* about 3MB -> 512 bytes */ - bpb.spc = 1; - else if (bpb.bsec <= (1<<17)) /* 64M -> 4k */ - bpb.spc = 8; - else if (bpb.bsec <= (1<<19)) /* 256M -> 8k */ - bpb.spc = 16; - else if (bpb.bsec <= (1<<21)) /* 1G -> 16k */ - bpb.spc = 32; + if (bpb.bpbSecPerClust == 0) { /* set defaults */ + if (bpb.bpbHugeSectors <= 6000) /* about 3MB -> 512 bytes */ + bpb.bpbSecPerClust = 1; + else if (bpb.bpbHugeSectors <= (1<<17)) /* 64M -> 4k */ + bpb.bpbSecPerClust = 8; + else if (bpb.bpbHugeSectors <= (1<<19)) /* 256M -> 8k */ + bpb.bpbSecPerClust = 16; + else if (bpb.bpbHugeSectors <= (1<<21)) /* 1G -> 16k */ + bpb.bpbSecPerClust = 32; else - bpb.spc = 64; /* otherwise 32k */ + bpb.bpbSecPerClust = 64; /* otherwise 32k */ } } - if (!powerof2(bpb.bps)) - errx(1, "bytes/sector (%u) is not a power of 2", bpb.bps); - if (bpb.bps < MINBPS) + if (!powerof2(bpb.bpbBytesPerSec)) + errx(1, "bytes/sector (%u) is not a power of 2", bpb.bpbBytesPerSec); + if (bpb.bpbBytesPerSec < MINBPS) errx(1, "bytes/sector (%u) is too small; minimum is %u", - bpb.bps, MINBPS); + bpb.bpbBytesPerSec, MINBPS); if (!(fat = opt_F)) { if (opt_f) fat = 12; @@ -435,44 +439,44 @@ main(int argc, char *argv[]) fat == 32 ? 'e' : opt_i ? 'i' : 'k', fat == 32 ? "32" : "12/16"); if (opt_f && fat == 32) - bpb.rde = 0; + bpb.bpbRootDirEnts = 0; if (opt_b) { if (!powerof2(opt_b)) errx(1, "block size (%u) is not a power of 2", opt_b); - if (opt_b < bpb.bps) + if (opt_b < bpb.bpbBytesPerSec) errx(1, "block size (%u) is too small; minimum is %u", - opt_b, bpb.bps); - if (opt_b > bpb.bps * MAXSPC) + opt_b, bpb.bpbBytesPerSec); + if (opt_b > bpb.bpbBytesPerSec * MAXSPC) errx(1, "block size (%u) is too large; maximum is %u", - opt_b, bpb.bps * MAXSPC); - bpb.spc = opt_b / bpb.bps; + opt_b, bpb.bpbBytesPerSec * MAXSPC); + bpb.bpbSecPerClust = opt_b / bpb.bpbBytesPerSec; } if (opt_c) { if (!powerof2(opt_c)) errx(1, "sectors/cluster (%u) is not a power of 2", opt_c); - bpb.spc = opt_c; + bpb.bpbSecPerClust = opt_c; } if (opt_r) - bpb.res = opt_r; + bpb.bpbResSectors = opt_r; if (opt_n) { if (opt_n > MAXNFT) errx(1, "number of FATs (%u) is too large; maximum is %u", opt_n, MAXNFT); - bpb.nft = opt_n; + bpb.bpbFATs = opt_n; } if (opt_e) - bpb.rde = opt_e; + bpb.bpbRootDirEnts = opt_e; if (mflag) { if (opt_m < 0xf0) errx(1, "illegal media descriptor (%#x)", opt_m); - bpb.mid = opt_m; + bpb.bpbMedia = opt_m; } if (opt_a) - bpb.bspf = opt_a; + bpb.bpbBigFATsecs = opt_a; if (opt_i) - bpb.infs = opt_i; + bpb.bpbFSInfo = opt_i; if (opt_k) - bpb.bkbs = opt_k; + bpb.bpbBackup = opt_k; bss = 1; bname = NULL; fd1 = -1; @@ -485,87 +489,87 @@ main(int argc, char *argv[]) } if ((fd1 = open(bname, O_RDONLY)) == -1 || fstat(fd1, &sb)) err(1, "%s", bname); - if (!S_ISREG(sb.st_mode) || sb.st_size % bpb.bps || - sb.st_size < bpb.bps || sb.st_size > bpb.bps * MAXU16) + if (!S_ISREG(sb.st_mode) || sb.st_size % bpb.bpbBytesPerSec || + sb.st_size < bpb.bpbBytesPerSec || sb.st_size > bpb.bpbBytesPerSec * MAXU16) errx(1, "%s: inappropriate file type or format", bname); - bss = sb.st_size / bpb.bps; + bss = sb.st_size / bpb.bpbBytesPerSec; } - if (!bpb.nft) - bpb.nft = 2; + if (!bpb.bpbFATs) + bpb.bpbFATs = 2; if (!fat) { - if (bpb.bsec < (bpb.res ? bpb.res : bss) + - howmany((RESFTE + (bpb.spc ? MINCLS16 : MAXCLS12 + 1)) * - ((bpb.spc ? 16 : 12) / BPN), bpb.bps * NPB) * - bpb.nft + - howmany(bpb.rde ? bpb.rde : DEFRDE, - bpb.bps / sizeof(struct de)) + - (bpb.spc ? MINCLS16 : MAXCLS12 + 1) * - (bpb.spc ? bpb.spc : howmany(DEFBLK, bpb.bps))) + if (bpb.bpbHugeSectors < (bpb.bpbResSectors ? bpb.bpbResSectors : bss) + + howmany((RESFTE + (bpb.bpbSecPerClust ? MINCLS16 : MAXCLS12 + 1)) * + ((bpb.bpbSecPerClust ? 16 : 12) / BPN), bpb.bpbBytesPerSec * NPB) * + bpb.bpbFATs + + howmany(bpb.bpbRootDirEnts ? bpb.bpbRootDirEnts : DEFRDE, + bpb.bpbBytesPerSec / sizeof(struct de)) + + (bpb.bpbSecPerClust ? MINCLS16 : MAXCLS12 + 1) * + (bpb.bpbSecPerClust ? bpb.bpbSecPerClust : howmany(DEFBLK, bpb.bpbBytesPerSec))) fat = 12; - else if (bpb.rde || bpb.bsec < - (bpb.res ? bpb.res : bss) + - howmany((RESFTE + MAXCLS16) * 2, bpb.bps) * bpb.nft + - howmany(DEFRDE, bpb.bps / sizeof(struct de)) + + else if (bpb.bpbRootDirEnts || bpb.bpbHugeSectors < + (bpb.bpbResSectors ? bpb.bpbResSectors : bss) + + howmany((RESFTE + MAXCLS16) * 2, bpb.bpbBytesPerSec) * bpb.bpbFATs + + howmany(DEFRDE, bpb.bpbBytesPerSec / sizeof(struct de)) + (MAXCLS16 + 1) * - (bpb.spc ? bpb.spc : howmany(8192, bpb.bps))) + (bpb.bpbSecPerClust ? bpb.bpbSecPerClust : howmany(8192, bpb.bpbBytesPerSec))) fat = 16; else fat = 32; } x = bss; if (fat == 32) { - if (!bpb.infs) { - if (x == MAXU16 || x == bpb.bkbs) + if (!bpb.bpbFSInfo) { + if (x == MAXU16 || x == bpb.bpbBackup) errx(1, "no room for info sector"); - bpb.infs = x; + bpb.bpbFSInfo = x; } - if (bpb.infs != MAXU16 && x <= bpb.infs) - x = bpb.infs + 1; - if (!bpb.bkbs) { + if (bpb.bpbFSInfo != MAXU16 && x <= bpb.bpbFSInfo) + x = bpb.bpbFSInfo + 1; + if (!bpb.bpbBackup) { if (x == MAXU16) errx(1, "no room for backup sector"); - bpb.bkbs = x; - } else if (bpb.bkbs != MAXU16 && bpb.bkbs == bpb.infs) + bpb.bpbBackup = x; + } else if (bpb.bpbBackup != MAXU16 && bpb.bpbBackup == bpb.bpbFSInfo) errx(1, "backup sector would overwrite info sector"); - if (bpb.bkbs != MAXU16 && x <= bpb.bkbs) - x = bpb.bkbs + 1; + if (bpb.bpbBackup != MAXU16 && x <= bpb.bpbBackup) + x = bpb.bpbBackup + 1; } - if (!bpb.res) - bpb.res = fat == 32 ? MAX(x, MAX(16384 / bpb.bps, 4)) : x; - else if (bpb.res < x) - errx(1, "too few reserved sectors"); - if (fat != 32 && !bpb.rde) - bpb.rde = DEFRDE; - rds = howmany(bpb.rde, bpb.bps / sizeof(struct de)); - if (!bpb.spc) - for (bpb.spc = howmany(fat == 16 ? DEFBLK16 : DEFBLK, bpb.bps); - bpb.spc < MAXSPC && - bpb.res + + if (!bpb.bpbResSectors) + bpb.bpbResSectors = fat == 32 ? MAX(x, MAX(16384 / bpb.bpbBytesPerSec, 4)) : x; + else if (bpb.bpbResSectors < x) + errx(1, "too few reserved sectors (need %d have %d)", x, bpb.bpbResSectors); + if (fat != 32 && !bpb.bpbRootDirEnts) + bpb.bpbRootDirEnts = DEFRDE; + rds = howmany(bpb.bpbRootDirEnts, bpb.bpbBytesPerSec / sizeof(struct de)); + if (!bpb.bpbSecPerClust) + for (bpb.bpbSecPerClust = howmany(fat == 16 ? DEFBLK16 : DEFBLK, bpb.bpbBytesPerSec); + bpb.bpbSecPerClust < MAXSPC && + bpb.bpbResSectors + howmany((RESFTE + maxcls(fat)) * (fat / BPN), - bpb.bps * NPB) * bpb.nft + + bpb.bpbBytesPerSec * NPB) * bpb.bpbFATs + rds + - (u_int64_t)(maxcls(fat) + 1) * bpb.spc <= bpb.bsec; - bpb.spc <<= 1); - if (fat != 32 && bpb.bspf > MAXU16) + (u_int64_t)(maxcls(fat) + 1) * bpb.bpbSecPerClust <= bpb.bpbHugeSectors; + bpb.bpbSecPerClust <<= 1); + if (fat != 32 && bpb.bpbBigFATsecs > MAXU16) errx(1, "too many sectors/FAT for FAT12/16"); - x1 = bpb.res + rds; - x = bpb.bspf ? bpb.bspf : 1; - if (x1 + (u_int64_t)x * bpb.nft > bpb.bsec) + x1 = bpb.bpbResSectors + rds; + x = bpb.bpbBigFATsecs ? bpb.bpbBigFATsecs : 1; + if (x1 + (u_int64_t)x * bpb.bpbFATs > bpb.bpbHugeSectors) errx(1, "meta data exceeds file system size"); - x1 += x * bpb.nft; - x = (u_int64_t)(bpb.bsec - x1) * bpb.bps * NPB / - (bpb.spc * bpb.bps * NPB + fat / BPN * bpb.nft); + x1 += x * bpb.bpbFATs; + x = (u_int64_t)(bpb.bpbHugeSectors - x1) * bpb.bpbBytesPerSec * NPB / + (bpb.bpbSecPerClust * bpb.bpbBytesPerSec * NPB + fat / BPN * bpb.bpbFATs); x2 = howmany((RESFTE + MIN(x, maxcls(fat))) * (fat / BPN), - bpb.bps * NPB); - if (!bpb.bspf) { - bpb.bspf = x2; - x1 += (bpb.bspf - 1) * bpb.nft; + bpb.bpbBytesPerSec * NPB); + if (!bpb.bpbBigFATsecs) { + bpb.bpbBigFATsecs = x2; + x1 += (bpb.bpbBigFATsecs - 1) * bpb.bpbFATs; } - cls = (bpb.bsec - x1) / bpb.spc; - x = (u_int64_t)bpb.bspf * bpb.bps * NPB / (fat / BPN) - RESFTE; + cls = (bpb.bpbHugeSectors - x1) / bpb.bpbSecPerClust; + x = (u_int64_t)bpb.bpbBigFATsecs * bpb.bpbBytesPerSec * NPB / (fat / BPN) - RESFTE; if (cls > x) cls = x; - if (bpb.bspf < x2) + if (bpb.bpbBigFATsecs < x2) warnx("warning: sectors/FAT limits file system to %u clusters", cls); if (cls < mincls(fat)) @@ -573,79 +577,79 @@ main(int argc, char *argv[]) mincls(fat)); if (cls > maxcls(fat)) { cls = maxcls(fat); - bpb.bsec = x1 + (cls + 1) * bpb.spc - 1; + bpb.bpbHugeSectors = x1 + (cls + 1) * bpb.bpbSecPerClust - 1; warnx("warning: FAT type limits file system to %u sectors", - bpb.bsec); + bpb.bpbHugeSectors); } printf("%s: %u sector%s in %u FAT%u cluster%s " - "(%u bytes/cluster)\n", fname, cls * bpb.spc, - cls * bpb.spc == 1 ? "" : "s", cls, fat, - cls == 1 ? "" : "s", bpb.bps * bpb.spc); - if (!bpb.mid) - bpb.mid = !bpb.hid ? 0xf0 : 0xf8; + "(%u bytes/cluster)\n", fname, cls * bpb.bpbSecPerClust, + cls * bpb.bpbSecPerClust == 1 ? "" : "s", cls, fat, + cls == 1 ? "" : "s", bpb.bpbBytesPerSec * bpb.bpbSecPerClust); + if (!bpb.bpbMedia) + bpb.bpbMedia = !bpb.bpbHiddenSecs ? 0xf0 : 0xf8; if (fat == 32) - bpb.rdcl = RESFTE; - if (bpb.hid + bpb.bsec <= MAXU16) { - bpb.sec = bpb.bsec; - bpb.bsec = 0; + bpb.bpbRootClust = RESFTE; + if (bpb.bpbHiddenSecs + bpb.bpbHugeSectors <= MAXU16) { + bpb.bpbSectors = bpb.bpbHugeSectors; + bpb.bpbHugeSectors = 0; } if (fat != 32) { - bpb.spf = bpb.bspf; - bpb.bspf = 0; + bpb.bpbFATsecs = bpb.bpbBigFATsecs; + bpb.bpbBigFATsecs = 0; } print_bpb(&bpb); if (!opt_N) { gettimeofday(&tv, NULL); now = tv.tv_sec; tm = localtime(&now); - if (!(img = malloc(bpb.bps))) + if (!(img = malloc(bpb.bpbBytesPerSec))) err(1, NULL); - dir = bpb.res + (bpb.spf ? bpb.spf : bpb.bspf) * bpb.nft; - for (lsn = 0; lsn < dir + (fat == 32 ? bpb.spc : rds); lsn++) { + dir = bpb.bpbResSectors + (bpb.bpbFATsecs ? bpb.bpbFATsecs : bpb.bpbBigFATsecs) * bpb.bpbFATs; + for (lsn = 0; lsn < dir + (fat == 32 ? bpb.bpbSecPerClust : rds); lsn++) { x = lsn; if (opt_B && - fat == 32 && bpb.bkbs != MAXU16 && - bss <= bpb.bkbs && x >= bpb.bkbs) { - x -= bpb.bkbs; + fat == 32 && bpb.bpbBackup != MAXU16 && + bss <= bpb.bpbBackup && x >= bpb.bpbBackup) { + x -= bpb.bpbBackup; if (!x && lseek(fd1, opt_ofs, SEEK_SET)) err(1, "%s", bname); } if (opt_B && x < bss) { - if ((n = read(fd1, img, bpb.bps)) == -1) + if ((n = read(fd1, img, bpb.bpbBytesPerSec)) == -1) err(1, "%s", bname); - if ((unsigned)n != bpb.bps) + if ((unsigned)n != bpb.bpbBytesPerSec) errx(1, "%s: can't read sector %u", bname, x); } else - memset(img, 0, bpb.bps); + memset(img, 0, bpb.bpbBytesPerSec); if (!lsn || - (fat == 32 && bpb.bkbs != MAXU16 && lsn == bpb.bkbs)) { + (fat == 32 && bpb.bpbBackup != MAXU16 && lsn == bpb.bpbBackup)) { x1 = sizeof(struct bs); bsbpb = (struct bsbpb *)(img + x1); - mk2(bsbpb->bps, bpb.bps); - mk1(bsbpb->spc, bpb.spc); - mk2(bsbpb->res, bpb.res); - mk1(bsbpb->nft, bpb.nft); - mk2(bsbpb->rde, bpb.rde); - mk2(bsbpb->sec, bpb.sec); - mk1(bsbpb->mid, bpb.mid); - mk2(bsbpb->spf, bpb.spf); - mk2(bsbpb->spt, bpb.spt); - mk2(bsbpb->hds, bpb.hds); - mk4(bsbpb->hid, bpb.hid); - mk4(bsbpb->bsec, bpb.bsec); + mk2(bsbpb->bpbBytesPerSec, bpb.bpbBytesPerSec); + mk1(bsbpb->bpbSecPerClust, bpb.bpbSecPerClust); + mk2(bsbpb->bpbResSectors, bpb.bpbResSectors); + mk1(bsbpb->bpbFATs, bpb.bpbFATs); + mk2(bsbpb->bpbRootDirEnts, bpb.bpbRootDirEnts); + mk2(bsbpb->bpbSectors, bpb.bpbSectors); + mk1(bsbpb->bpbMedia, bpb.bpbMedia); + mk2(bsbpb->bpbFATsecs, bpb.bpbFATsecs); + mk2(bsbpb->bpbSecPerTrack, bpb.bpbSecPerTrack); + mk2(bsbpb->bpbHeads, bpb.bpbHeads); + mk4(bsbpb->bpbHiddenSecs, bpb.bpbHiddenSecs); + mk4(bsbpb->bpbHugeSectors, bpb.bpbHugeSectors); x1 += sizeof(struct bsbpb); if (fat == 32) { bsxbpb = (struct bsxbpb *)(img + x1); - mk4(bsxbpb->bspf, bpb.bspf); + mk4(bsxbpb->bspf, bpb.bpbBigFATsecs); mk2(bsxbpb->xflg, 0); mk2(bsxbpb->vers, 0); - mk4(bsxbpb->rdcl, bpb.rdcl); - mk2(bsxbpb->infs, bpb.infs); - mk2(bsxbpb->bkbs, bpb.bkbs); + mk4(bsxbpb->rdcl, bpb.bpbRootClust); + mk2(bsxbpb->infs, bpb.bpbFSInfo); + mk2(bsxbpb->bkbs, bpb.bpbBackup); x1 += sizeof(struct bsxbpb); } bsx = (struct bsx *)(img + x1); - mk1(bsx->sig, 0x29); + mk1(bsx->exBootSignature, 0x29); if (Iflag) x = opt_I; else @@ -656,52 +660,52 @@ main(int argc, char *argv[]) ((u_int)(1900 + tm->tm_year) + ((u_int)tm->tm_hour << 8 | (u_int)tm->tm_min)); - mk4(bsx->volid, x); - mklabel(bsx->label, opt_L ? opt_L : "NO NAME"); + mk4(bsx->exVolumeID, x); + mklabel(bsx->exVolumeLabel, opt_L ? opt_L : "NO_NAME"); sprintf(buf, "FAT%u", fat); - setstr(bsx->type, buf, sizeof(bsx->type)); + setstr(bsx->exFileSysType, buf, sizeof(bsx->exFileSysType)); if (!opt_B) { x1 += sizeof(struct bsx); bs = (struct bs *)img; - mk1(bs->jmp[0], 0xeb); - mk1(bs->jmp[1], x1 - 2); - mk1(bs->jmp[2], 0x90); - setstr(bs->oem, opt_O ? opt_O : "BSD 4.4", - sizeof(bs->oem)); + mk1(bs->bsJump[0], 0xeb); + mk1(bs->bsJump[1], x1 - 2); + mk1(bs->bsJump[2], 0x90); + setstr(bs->bsOemName, opt_O ? opt_O : "BSD4.4 ", + sizeof(bs->bsOemName)); memcpy(img + x1, bootcode, sizeof(bootcode)); mk2(img + MINBPS - 2, DOSMAGIC); } - } else if (fat == 32 && bpb.infs != MAXU16 && - (lsn == bpb.infs || - (bpb.bkbs != MAXU16 && - lsn == bpb.bkbs + bpb.infs))) { + } else if (fat == 32 && bpb.bpbFSInfo != MAXU16 && + (lsn == bpb.bpbFSInfo || + (bpb.bpbBackup != MAXU16 && + lsn == bpb.bpbBackup + bpb.bpbFSInfo))) { mk4(img, 0x41615252); mk4(img + MINBPS - 28, 0x61417272); mk4(img + MINBPS - 24, 0xffffffff); - mk4(img + MINBPS - 20, bpb.rdcl); + mk4(img + MINBPS - 20, bpb.bpbRootClust); mk2(img + MINBPS - 2, DOSMAGIC); - } else if (lsn >= bpb.res && lsn < dir && - !((lsn - bpb.res) % - (bpb.spf ? bpb.spf : bpb.bspf))) { - mk1(img[0], bpb.mid); + } else if (lsn >= bpb.bpbResSectors && lsn < dir && + !((lsn - bpb.bpbResSectors) % + (bpb.bpbFATsecs ? bpb.bpbFATsecs : bpb.bpbBigFATsecs))) { + mk1(img[0], bpb.bpbMedia); for (x = 1; x < fat * (fat == 32 ? 3 : 2) / 8; x++) mk1(img[x], fat == 32 && x % 4 == 3 ? 0x0f : 0xff); } else if (lsn == dir && opt_L) { de = (struct de *)img; - mklabel(de->namext, opt_L); - mk1(de->attr, 050); + mklabel(de->deName, opt_L); + mk1(de->deAttributes, 050); x = (u_int)tm->tm_hour << 11 | (u_int)tm->tm_min << 5 | (u_int)tm->tm_sec >> 1; - mk2(de->time, x); + mk2(de->deCTime, x); x = (u_int)(tm->tm_year - 80) << 9 | (u_int)(tm->tm_mon + 1) << 5 | (u_int)tm->tm_mday; - mk2(de->date, x); + mk2(de->deCDate, x); } - if ((n = write(fd, img, bpb.bps)) == -1) + if ((n = write(fd, img, bpb.bpbBytesPerSec)) == -1) err(1, "%s", fname); - if ((unsigned)n != bpb.bps) + if ((unsigned)n != bpb.bpbBytesPerSec) errx(1, "%s: can't write sector %u", fname, lsn); } } @@ -794,18 +798,19 @@ getdiskinfo(int fd, const char *fname, const char *dtype, __unused int oflag, /* Maybe it's a fixed drive */ if (lp == NULL) { + if (bpb->bpbBytesPerSec) + dlp.d_secsize = bpb->bpbBytesPerSec; if (ioctl(fd, DIOCGDINFO, &dlp) == -1) { - if (bpb->bps == 0 && ioctl(fd, DIOCGSECTORSIZE, &dlp.d_secsize) == -1) + if (bpb->bpbBytesPerSec == 0 && ioctl(fd, DIOCGSECTORSIZE, &dlp.d_secsize) == -1) errx(1, "Cannot get sector size, %s", strerror(errno)); - /* XXX Should we use bpb->bps if it's set? */ dlp.d_secperunit = ms / dlp.d_secsize; - if (bpb->spt == 0 && ioctl(fd, DIOCGFWSECTORS, &dlp.d_nsectors) == -1) { + if (bpb->bpbSecPerTrack == 0 && ioctl(fd, DIOCGFWSECTORS, &dlp.d_nsectors) == -1) { warnx("Cannot get number of sectors per track, %s", strerror(errno)); dlp.d_nsectors = 63; } - if (bpb->hds == 0 && ioctl(fd, DIOCGFWHEADS, &dlp.d_ntracks) == -1) { + if (bpb->bpbHeads == 0 && ioctl(fd, DIOCGFWHEADS, &dlp.d_ntracks) == -1) { warnx("Cannot get number of heads, %s", strerror(errno)); if (dlp.d_secperunit <= 63*1*1024) dlp.d_ntracks = 1; @@ -820,16 +825,16 @@ getdiskinfo(int fd, const char *fname, const char *dtype, __unused int oflag, lp = &dlp; } - if (bpb->bps == 0) - bpb->bps = ckgeom(fname, lp->d_secsize, "bytes/sector"); - if (bpb->spt == 0) - bpb->spt = ckgeom(fname, lp->d_nsectors, "sectors/track"); - if (bpb->hds == 0) - bpb->hds = ckgeom(fname, lp->d_ntracks, "drive heads"); - if (bpb->bsec == 0) - bpb->bsec = lp->d_secperunit; - if (bpb->hid == 0) - bpb->hid = hs; + if (bpb->bpbBytesPerSec == 0) + bpb->bpbBytesPerSec = ckgeom(fname, lp->d_secsize, "bytes/sector"); + if (bpb->bpbSecPerTrack == 0) + bpb->bpbSecPerTrack = ckgeom(fname, lp->d_nsectors, "sectors/track"); + if (bpb->bpbHeads == 0) + bpb->bpbHeads = ckgeom(fname, lp->d_ntracks, "drive heads"); + if (bpb->bpbHugeSectors == 0) + bpb->bpbHugeSectors = lp->d_secperunit; + if (bpb->bpbHiddenSecs == 0) + bpb->bpbHiddenSecs = hs; } /* @@ -838,24 +843,24 @@ getdiskinfo(int fd, const char *fname, const char *dtype, __unused int oflag, static void print_bpb(struct bpb *bpb) { - printf("bps=%u spc=%u res=%u nft=%u", bpb->bps, bpb->spc, bpb->res, - bpb->nft); - if (bpb->rde) - printf(" rde=%u", bpb->rde); - if (bpb->sec) - printf(" sec=%u", bpb->sec); - printf(" mid=%#x", bpb->mid); - if (bpb->spf) - printf(" spf=%u", bpb->spf); - printf(" spt=%u hds=%u hid=%u", bpb->spt, bpb->hds, bpb->hid); - if (bpb->bsec) - printf(" bsec=%u", bpb->bsec); - if (!bpb->spf) { - printf(" bspf=%u rdcl=%u", bpb->bspf, bpb->rdcl); - printf(" infs="); - printf(bpb->infs == MAXU16 ? "%#x" : "%u", bpb->infs); - printf(" bkbs="); - printf(bpb->bkbs == MAXU16 ? "%#x" : "%u", bpb->bkbs); + printf("BytesPerSec=%u SecPerClust=%u ResSectors=%u FATs=%u", bpb->bpbBytesPerSec, bpb->bpbSecPerClust, bpb->bpbResSectors, + bpb->bpbFATs); + if (bpb->bpbRootDirEnts) + printf(" RootDirEnts=%u", bpb->bpbRootDirEnts); + if (bpb->bpbSectors) + printf(" Sectors=%u", bpb->bpbSectors); + printf(" Media=%#x", bpb->bpbMedia); + if (bpb->bpbFATsecs) + printf(" FATsecs=%u", bpb->bpbFATsecs); + printf(" SecPerTrack=%u Heads=%u HiddenSecs=%u", bpb->bpbSecPerTrack, bpb->bpbHeads, bpb->bpbHiddenSecs); + if (bpb->bpbHugeSectors) + printf(" HugeSectors=%u", bpb->bpbHugeSectors); + if (!bpb->bpbFATsecs) { + printf(" FATsecs=%u RootCluster=%u", bpb->bpbBigFATsecs, bpb->bpbRootClust); + printf(" FSInfo="); + printf(bpb->bpbFSInfo == MAXU16 ? "%#x" : "%u", bpb->bpbFSInfo); + printf(" Backup="); + printf(bpb->bpbBackup == MAXU16 ? "%#x" : "%u", bpb->bpbBackup); } printf("\n"); } diff --git a/sys/cddl/compat/opensolaris/kern/opensolaris_kobj.c b/sys/cddl/compat/opensolaris/kern/opensolaris_kobj.c index d794345..1ef151a 100644 --- a/sys/cddl/compat/opensolaris/kern/opensolaris_kobj.c +++ b/sys/cddl/compat/opensolaris/kern/opensolaris_kobj.c @@ -69,7 +69,7 @@ kobj_open_file_vnode(const char *file) struct thread *td = curthread; struct filedesc *fd; struct nameidata nd; - int error, flags, vfslocked; + int error, flags; fd = td->td_proc->p_fd; FILEDESC_XLOCK(fd); @@ -84,15 +84,13 @@ kobj_open_file_vnode(const char *file) FILEDESC_XUNLOCK(fd); flags = FREAD | O_NOFOLLOW; - NDINIT(&nd, LOOKUP, MPSAFE, UIO_SYSSPACE, file, td); + NDINIT(&nd, LOOKUP, 0, UIO_SYSSPACE, file, td); error = vn_open_cred(&nd, &flags, 0, 0, curthread->td_ucred, NULL); if (error != 0) return (NULL); - vfslocked = NDHASGIANT(&nd); NDFREE(&nd, NDF_ONLY_PNBUF); /* We just unlock so we hold a reference. */ VOP_UNLOCK(nd.ni_vp, 0); - VFS_UNLOCK_GIANT(vfslocked); return (nd.ni_vp); } @@ -130,15 +128,13 @@ kobj_get_filesize_vnode(struct _buf *file, uint64_t *size) { struct vnode *vp = file->ptr; struct vattr va; - int error, vfslocked; + int error; - vfslocked = VFS_LOCK_GIANT(vp->v_mount); vn_lock(vp, LK_SHARED | LK_RETRY); error = VOP_GETATTR(vp, &va, curthread->td_ucred); VOP_UNLOCK(vp, 0); if (error == 0) *size = (uint64_t)va.va_size; - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -171,7 +167,7 @@ kobj_read_file_vnode(struct _buf *file, char *buf, unsigned size, unsigned off) struct thread *td = curthread; struct uio auio; struct iovec aiov; - int error, vfslocked; + int error; bzero(&aiov, sizeof(aiov)); bzero(&auio, sizeof(auio)); @@ -187,11 +183,9 @@ kobj_read_file_vnode(struct _buf *file, char *buf, unsigned size, unsigned off) auio.uio_resid = size; auio.uio_td = td; - vfslocked = VFS_LOCK_GIANT(vp->v_mount); vn_lock(vp, LK_SHARED | LK_RETRY); error = VOP_READ(vp, &auio, IO_UNIT | IO_SYNC, td->td_ucred); VOP_UNLOCK(vp, 0); - VFS_UNLOCK_GIANT(vfslocked); return (error != 0 ? -1 : size - auio.uio_resid); } @@ -222,14 +216,7 @@ void kobj_close_file(struct _buf *file) { - if (file->mounted) { - struct vnode *vp = file->ptr; - struct thread *td = curthread; - int vfslocked; - - vfslocked = VFS_LOCK_GIANT(vp->v_mount); - vn_close(vp, FREAD, td->td_ucred, td); - VFS_UNLOCK_GIANT(vfslocked); - } + if (file->mounted) + vn_close(file->ptr, FREAD, curthread->td_ucred, curthread); kmem_free(file, sizeof(*file)); } diff --git a/sys/cddl/compat/opensolaris/kern/opensolaris_lookup.c b/sys/cddl/compat/opensolaris/kern/opensolaris_lookup.c index ba79027..a7ec8b9 100644 --- a/sys/cddl/compat/opensolaris/kern/opensolaris_lookup.c +++ b/sys/cddl/compat/opensolaris/kern/opensolaris_lookup.c @@ -54,7 +54,7 @@ lookupnameat(char *dirname, enum uio_seg seg, enum symfollow follow, vref(startvp); ltype = VOP_ISLOCKED(startvp); VOP_UNLOCK(startvp, 0); - NDINIT_ATVP(&nd, LOOKUP, LOCKLEAF | MPSAFE | follow, seg, dirname, + NDINIT_ATVP(&nd, LOOKUP, LOCKLEAF | follow, seg, dirname, startvp, curthread); error = namei(&nd); *compvpp = nd.ni_vp; diff --git a/sys/cddl/compat/opensolaris/sys/vnode.h b/sys/cddl/compat/opensolaris/sys/vnode.h index 7296635..8938c1e 100644 --- a/sys/cddl/compat/opensolaris/sys/vnode.h +++ b/sys/cddl/compat/opensolaris/sys/vnode.h @@ -181,7 +181,7 @@ vn_openat(char *pnamep, enum uio_seg seg, int filemode, int createmode, if (startvp != NULL) vref(startvp); - NDINIT_ATVP(&nd, operation, MPSAFE, UIO_SYSSPACE, pnamep, startvp, td); + NDINIT_ATVP(&nd, operation, 0, UIO_SYSSPACE, pnamep, startvp, td); filemode |= O_NOFOLLOW; error = vn_open_cred(&nd, &filemode, createmode, 0, td->td_ucred, NULL); NDFREE(&nd, NDF_ONLY_PNBUF); @@ -211,12 +211,11 @@ zfs_vn_rdwr(enum uio_rw rw, vnode_t *vp, caddr_t base, ssize_t len, ssize_t *residp) { struct thread *td = curthread; - int error, vfslocked, resid; + int error, resid; ASSERT(ioflag == 0); ASSERT(ulimit == RLIM64_INFINITY); - vfslocked = VFS_LOCK_GIANT(vp->v_mount); if (rw == UIO_WRITE) { ioflag = IO_SYNC; } else { @@ -224,7 +223,6 @@ zfs_vn_rdwr(enum uio_rw rw, vnode_t *vp, caddr_t base, ssize_t len, } error = vn_rdwr(rw, vp, base, len, offset, seg, ioflag, cr, NOCRED, &resid, td); - VFS_UNLOCK_GIANT(vfslocked); if (residp != NULL) *residp = (ssize_t)resid; return (error); @@ -236,11 +234,10 @@ static __inline int zfs_vop_fsync(vnode_t *vp, int flag, cred_t *cr) { struct mount *mp; - int error, vfslocked; + int error; ASSERT(flag == FSYNC); - vfslocked = VFS_LOCK_GIANT(vp->v_mount); if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0) goto drop; vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); @@ -248,7 +245,6 @@ zfs_vop_fsync(vnode_t *vp, int flag, cred_t *cr) VOP_UNLOCK(vp, 0); vn_finished_write(mp); drop: - VFS_UNLOCK_GIANT(vfslocked); return (error); } #define VOP_FSYNC(vp, flag, cr, ct) zfs_vop_fsync((vp), (flag), (cr)) @@ -256,14 +252,12 @@ drop: static __inline int zfs_vop_close(vnode_t *vp, int flag, int count, offset_t offset, cred_t *cr) { - int error, vfslocked; + int error; ASSERT(count == 1); ASSERT(offset == 0); - vfslocked = VFS_LOCK_GIANT(vp->v_mount); error = vn_close(vp, flag, cr, curthread); - VFS_UNLOCK_GIANT(vfslocked); return (error); } #define VOP_CLOSE(vp, oflags, count, offset, cr, ct) \ diff --git a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_file.c b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_file.c index 30b3f35..61bb2f6 100644 --- a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_file.c +++ b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/vdev_file.c @@ -41,7 +41,7 @@ vdev_file_open(vdev_t *vd, uint64_t *psize, uint64_t *ashift) vdev_file_t *vf; vnode_t *vp; vattr_t vattr; - int error, vfslocked; + int error; /* * We must have a pathname, and it must be absolute. @@ -84,11 +84,9 @@ vdev_file_open(vdev_t *vd, uint64_t *psize, uint64_t *ashift) * Determine the physical size of the file. */ vattr.va_mask = AT_SIZE; - vfslocked = VFS_LOCK_GIANT(vp->v_mount); vn_lock(vp, LK_SHARED | LK_RETRY); error = VOP_GETATTR(vp, &vattr, kcred); VOP_UNLOCK(vp, 0); - VFS_UNLOCK_GIANT(vfslocked); if (error) { (void) VOP_CLOSE(vp, spa_mode, 1, 0, kcred, NULL); vd->vdev_stat.vs_aux = VDEV_AUX_OPEN_FAILED; diff --git a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c index 4f61f5f..603ac17 100644 --- a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c +++ b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vnops.c @@ -925,9 +925,7 @@ zfs_get_done(dmu_buf_t *db, void *vzgd) rl_t *rl = zgd->zgd_rl; vnode_t *vp = ZTOV(rl->r_zp); objset_t *os = rl->r_zp->z_zfsvfs->z_os; - int vfslocked; - vfslocked = VFS_LOCK_GIANT(vp->v_vfsp); dmu_buf_rele(db, vzgd); zfs_range_unlock(rl); /* @@ -937,7 +935,6 @@ zfs_get_done(dmu_buf_t *db, void *vzgd) VN_RELE_ASYNC(vp, dsl_pool_vnrele_taskq(dmu_objset_pool(os))); zil_add_block(zgd->zgd_zilog, zgd->zgd_bp); kmem_free(zgd, sizeof (zgd_t)); - VFS_UNLOCK_GIANT(vfslocked); } /* @@ -4598,7 +4595,7 @@ vop_getextattr { } flags = FREAD; - NDINIT_ATVP(&nd, LOOKUP, NOFOLLOW | MPSAFE, UIO_SYSSPACE, attrname, + NDINIT_ATVP(&nd, LOOKUP, NOFOLLOW, UIO_SYSSPACE, attrname, xvp, td); error = vn_open_cred(&nd, &flags, 0, 0, ap->a_cred, NULL); vp = nd.ni_vp; @@ -4666,7 +4663,7 @@ vop_deleteextattr { return (error); } - NDINIT_ATVP(&nd, DELETE, NOFOLLOW | LOCKPARENT | LOCKLEAF | MPSAFE, + NDINIT_ATVP(&nd, DELETE, NOFOLLOW | LOCKPARENT | LOCKLEAF, UIO_SYSSPACE, attrname, xvp, td); error = namei(&nd); vp = nd.ni_vp; @@ -4733,7 +4730,7 @@ vop_setextattr { } flags = FFLAGS(O_WRONLY | O_CREAT); - NDINIT_ATVP(&nd, LOOKUP, NOFOLLOW | MPSAFE, UIO_SYSSPACE, attrname, + NDINIT_ATVP(&nd, LOOKUP, NOFOLLOW, UIO_SYSSPACE, attrname, xvp, td); error = vn_open_cred(&nd, &flags, 0600, 0, ap->a_cred, NULL); vp = nd.ni_vp; @@ -4814,7 +4811,7 @@ vop_listextattr { return (error); } - NDINIT_ATVP(&nd, LOOKUP, NOFOLLOW | LOCKLEAF | LOCKSHARED | MPSAFE, + NDINIT_ATVP(&nd, LOOKUP, NOFOLLOW | LOCKLEAF | LOCKSHARED, UIO_SYSSPACE, ".", xvp, td); error = namei(&nd); vp = nd.ni_vp; diff --git a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_znode.c b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_znode.c index 900087b..7157930 100644 --- a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_znode.c +++ b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_znode.c @@ -1017,7 +1017,6 @@ zfs_zinactive(znode_t *zp) vnode_t *vp = ZTOV(zp); zfsvfs_t *zfsvfs = zp->z_zfsvfs; uint64_t z_id = zp->z_id; - int vfslocked; ASSERT(zp->z_dbuf && zp->z_phys); @@ -1050,9 +1049,7 @@ zfs_zinactive(znode_t *zp) ZFS_OBJ_HOLD_EXIT(zfsvfs, z_id); ASSERT(vp->v_count == 0); vrecycle(vp, curthread); - vfslocked = VFS_LOCK_GIANT(zfsvfs->z_vfs); zfs_rmnode(zp); - VFS_UNLOCK_GIANT(vfslocked); return; } mutex_exit(&zp->z_lock); diff --git a/sys/compat/linprocfs/linprocfs.c b/sys/compat/linprocfs/linprocfs.c index 541db2f..4859a3a 100644 --- a/sys/compat/linprocfs/linprocfs.c +++ b/sys/compat/linprocfs/linprocfs.c @@ -325,7 +325,7 @@ linprocfs_domtab(PFS_FILL_ARGS) int error; /* resolve symlinks etc. in the emulation tree prefix */ - NDINIT(&nd, LOOKUP, FOLLOW | MPSAFE, UIO_SYSSPACE, linux_emul_path, td); + NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, linux_emul_path, td); flep = NULL; error = namei(&nd); lep = linux_emul_path; @@ -333,7 +333,6 @@ linprocfs_domtab(PFS_FILL_ARGS) if (vn_fullpath(td, nd.ni_vp, &dlep, &flep) == 0) lep = dlep; vrele(nd.ni_vp); - VFS_UNLOCK_GIANT(NDHASGIANT(&nd)); } lep_len = strlen(lep); @@ -404,7 +403,7 @@ linprocfs_dopartitions(PFS_FILL_ARGS) int major, minor; /* resolve symlinks etc. in the emulation tree prefix */ - NDINIT(&nd, LOOKUP, FOLLOW | MPSAFE, UIO_SYSSPACE, linux_emul_path, td); + NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, linux_emul_path, td); flep = NULL; error = namei(&nd); lep = linux_emul_path; @@ -412,7 +411,6 @@ linprocfs_dopartitions(PFS_FILL_ARGS) if (vn_fullpath(td, nd.ni_vp, &dlep, &flep) == 0) lep = dlep; vrele(nd.ni_vp); - VFS_UNLOCK_GIANT(NDHASGIANT(&nd)); } lep_len = strlen(lep); @@ -964,7 +962,6 @@ linprocfs_doprocmaps(PFS_FILL_ARGS) int error; struct vnode *vp; struct vattr vat; - int locked; PROC_LOCK(p); error = p_candebug(td, p); @@ -1017,12 +1014,10 @@ linprocfs_doprocmaps(PFS_FILL_ARGS) VM_OBJECT_UNLOCK(obj); if (vp) { vn_fullpath(td, vp, &name, &freename); - locked = VFS_LOCK_GIANT(vp->v_mount); vn_lock(vp, LK_SHARED | LK_RETRY); VOP_GETATTR(vp, &vat, td->td_ucred); ino = vat.va_fileid; vput(vp); - VFS_UNLOCK_GIANT(locked); } } else { flags = 0; diff --git a/sys/compat/linux/linux_file.c b/sys/compat/linux/linux_file.c index 4e33eaa..f2c7975 100644 --- a/sys/compat/linux/linux_file.c +++ b/sys/compat/linux/linux_file.c @@ -337,7 +337,7 @@ getdents_common(struct thread *td, struct linux_getdents64_args *args, struct l_dirent64 *linux_dirent64; int buflen, error, eofflag, nbytes, justone; u_long *cookies = NULL, *cookiep; - int ncookies, vfslocked; + int ncookies; nbytes = args->count; if (nbytes == 1) { @@ -358,9 +358,7 @@ getdents_common(struct thread *td, struct linux_getdents64_args *args, } vp = fp->f_vnode; - vfslocked = VFS_LOCK_GIANT(vp->v_mount); if (vp->v_type != VDIR) { - VFS_UNLOCK_GIANT(vfslocked); fdrop(fp, td); return (EINVAL); } @@ -525,7 +523,6 @@ out: free(cookies, M_TEMP); VOP_UNLOCK(vp, 0); - VFS_UNLOCK_GIANT(vfslocked); fdrop(fp, td); free(buf, M_TEMP); free(lbuf, M_TEMP); diff --git a/sys/compat/linux/linux_misc.c b/sys/compat/linux/linux_misc.c index d2cf6b6..c53f6e7 100644 --- a/sys/compat/linux/linux_misc.c +++ b/sys/compat/linux/linux_misc.c @@ -235,7 +235,7 @@ linux_uselib(struct thread *td, struct linux_uselib_args *args) unsigned long bss_size; char *library; int error; - int locked, vfslocked; + int locked; LCONVPATHEXIST(td, args->library, &library); @@ -245,11 +245,10 @@ linux_uselib(struct thread *td, struct linux_uselib_args *args) #endif a_out = NULL; - vfslocked = 0; locked = 0; vp = NULL; - NDINIT(&ni, LOOKUP, ISOPEN | FOLLOW | LOCKLEAF | MPSAFE | AUDITVNODE1, + NDINIT(&ni, LOOKUP, ISOPEN | FOLLOW | LOCKLEAF | AUDITVNODE1, UIO_SYSSPACE, library, td); error = namei(&ni); LFREEPATH(library); @@ -257,7 +256,6 @@ linux_uselib(struct thread *td, struct linux_uselib_args *args) goto cleanup; vp = ni.ni_vp; - vfslocked = NDHASGIANT(&ni); NDFREE(&ni, NDF_ONLY_PNBUF); /* @@ -379,7 +377,6 @@ linux_uselib(struct thread *td, struct linux_uselib_args *args) */ locked = 0; VOP_UNLOCK(vp, 0); - VFS_UNLOCK_GIANT(vfslocked); /* * Check if file_offset page aligned. Currently we cannot handle @@ -458,10 +455,8 @@ linux_uselib(struct thread *td, struct linux_uselib_args *args) cleanup: /* Unlock vnode if needed */ - if (locked) { + if (locked) VOP_UNLOCK(vp, 0); - VFS_UNLOCK_GIANT(vfslocked); - } /* Release the kernel mapping. */ if (a_out) diff --git a/sys/compat/ndis/subr_ndis.c b/sys/compat/ndis/subr_ndis.c index 558398d..82fd6ae 100644 --- a/sys/compat/ndis/subr_ndis.c +++ b/sys/compat/ndis/subr_ndis.c @@ -2741,7 +2741,7 @@ NdisOpenFile(status, filehandle, filelength, filename, highestaddr) char *afilename = NULL; struct thread *td = curthread; struct nameidata nd; - int flags, error, vfslocked; + int flags, error; struct vattr vat; struct vattr *vap = &vat; ndis_fh *fh; @@ -2821,7 +2821,7 @@ NdisOpenFile(status, filehandle, filelength, filename, highestaddr) if (td->td_proc->p_fd->fd_cdir == NULL) td->td_proc->p_fd->fd_cdir = rootvnode; - NDINIT(&nd, LOOKUP, FOLLOW | MPSAFE, UIO_SYSSPACE, path, td); + NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, path, td); flags = FREAD; error = vn_open(&nd, &flags, 0, NULL); @@ -2833,7 +2833,6 @@ NdisOpenFile(status, filehandle, filelength, filename, highestaddr) free(afilename, M_DEVBUF); return; } - vfslocked = NDHASGIANT(&nd); ExFreePool(path); @@ -2842,7 +2841,6 @@ NdisOpenFile(status, filehandle, filelength, filename, highestaddr) /* Get the file size. */ VOP_GETATTR(nd.ni_vp, vap, td->td_ucred); VOP_UNLOCK(nd.ni_vp, 0); - VFS_UNLOCK_GIANT(vfslocked); fh->nf_vp = nd.ni_vp; fh->nf_map = NULL; @@ -2862,7 +2860,7 @@ NdisMapFile(status, mappedbuffer, filehandle) struct thread *td = curthread; linker_file_t lf; caddr_t kldstart; - int error, resid, vfslocked; + int error, resid; struct vnode *vp; if (filehandle == NULL) { @@ -2902,10 +2900,8 @@ NdisMapFile(status, mappedbuffer, filehandle) } vp = fh->nf_vp; - vfslocked = VFS_LOCK_GIANT(vp->v_mount); error = vn_rdwr(UIO_READ, vp, fh->nf_map, fh->nf_maplen, 0, UIO_SYSSPACE, 0, td->td_ucred, NOCRED, &resid, td); - VFS_UNLOCK_GIANT(vfslocked); if (error) *status = NDIS_STATUS_FAILURE; @@ -2936,7 +2932,6 @@ NdisCloseFile(filehandle) { struct thread *td = curthread; ndis_fh *fh; - int vfslocked; struct vnode *vp; if (filehandle == NULL) @@ -2954,9 +2949,7 @@ NdisCloseFile(filehandle) if (fh->nf_type == NDIS_FH_TYPE_VFS) { vp = fh->nf_vp; - vfslocked = VFS_LOCK_GIANT(vp->v_mount); vn_close(vp, FREAD, td->td_ucred, td); - VFS_UNLOCK_GIANT(vfslocked); } fh->nf_vp = NULL; diff --git a/sys/compat/svr4/svr4_misc.c b/sys/compat/svr4/svr4_misc.c index 6f80fe6..fd48fe8 100644 --- a/sys/compat/svr4/svr4_misc.c +++ b/sys/compat/svr4/svr4_misc.c @@ -240,7 +240,7 @@ svr4_sys_getdents64(td, uap) struct iovec aiov; off_t off; struct svr4_dirent64 svr4_dirent; - int buflen, error, eofflag, nbytes, justone, vfslocked; + int buflen, error, eofflag, nbytes, justone; u_long *cookies = NULL, *cookiep; int ncookies; @@ -256,9 +256,7 @@ svr4_sys_getdents64(td, uap) } vp = fp->f_vnode; - vfslocked = VFS_LOCK_GIANT(vp->v_mount); if (vp->v_type != VDIR) { - VFS_UNLOCK_GIANT(vfslocked); fdrop(fp, td); return (EINVAL); } @@ -395,7 +393,6 @@ eof: td->td_retval[0] = nbytes - resid; out: VOP_UNLOCK(vp, 0); - VFS_UNLOCK_GIANT(vfslocked); fdrop(fp, td); if (cookies) free(cookies, M_TEMP); @@ -420,7 +417,7 @@ svr4_sys_getdents(td, uap) struct iovec aiov; struct svr4_dirent idb; off_t off; /* true file offset */ - int buflen, error, eofflag, vfslocked; + int buflen, error, eofflag; u_long *cookiebuf = NULL, *cookie; int ncookies = 0, *retval = td->td_retval; @@ -436,9 +433,7 @@ svr4_sys_getdents(td, uap) } vp = fp->f_vnode; - vfslocked = VFS_LOCK_GIANT(vp->v_mount); if (vp->v_type != VDIR) { - VFS_UNLOCK_GIANT(vfslocked); fdrop(fp, td); return (EINVAL); } @@ -531,7 +526,6 @@ eof: *retval = uap->nbytes - resid; out: VOP_UNLOCK(vp, 0); - VFS_UNLOCK_GIANT(vfslocked); fdrop(fp, td); if (cookiebuf) free(cookiebuf, M_TEMP); @@ -611,7 +605,7 @@ svr4_sys_fchroot(td, uap) struct filedesc *fdp = td->td_proc->p_fd; struct vnode *vp; struct file *fp; - int error, vfslocked; + int error; if ((error = priv_check(td, PRIV_VFS_FCHROOT)) != 0) return error; @@ -620,7 +614,6 @@ svr4_sys_fchroot(td, uap) vp = fp->f_vnode; VREF(vp); fdrop(fp, td); - vfslocked = VFS_LOCK_GIANT(vp->v_mount); vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); error = change_dir(vp, td); if (error) @@ -633,11 +626,9 @@ svr4_sys_fchroot(td, uap) VOP_UNLOCK(vp, 0); error = change_root(vp, td); vrele(vp); - VFS_UNLOCK_GIANT(vfslocked); return (error); fail: vput(vp); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -1648,13 +1639,12 @@ svr4_sys_resolvepath(td, uap) int error, *retval = td->td_retval; unsigned int ncopy; - NDINIT(&nd, LOOKUP, NOFOLLOW | SAVENAME | MPSAFE, UIO_USERSPACE, + NDINIT(&nd, LOOKUP, NOFOLLOW | SAVENAME, UIO_USERSPACE, uap->path, td); if ((error = namei(&nd)) != 0) return (error); NDFREE(&nd, NDF_NO_FREE_PNBUF); - VFS_UNLOCK_GIANT(NDHASGIANT(&nd)); ncopy = min(uap->bufsiz, strlen(nd.ni_cnd.cn_pnbuf) + 1); if ((error = copyout(nd.ni_cnd.cn_pnbuf, uap->buf, ncopy)) != 0) diff --git a/sys/dev/hwpmc/hwpmc_mod.c b/sys/dev/hwpmc/hwpmc_mod.c index d331a85..79bc04d 100644 --- a/sys/dev/hwpmc/hwpmc_mod.c +++ b/sys/dev/hwpmc/hwpmc_mod.c @@ -1626,7 +1626,6 @@ pmc_log_kernel_mappings(struct pmc *pm) static void pmc_log_process_mappings(struct pmc_owner *po, struct proc *p) { - int locked; vm_map_t map; struct vnode *vp; struct vmspace *vm; @@ -1736,9 +1735,7 @@ pmc_log_process_mappings(struct pmc_owner *po, struct proc *p) pmc_getfilename(vp, &fullpath, &freepath); last_vp = vp; - locked = VFS_LOCK_GIANT(vp->v_mount); vrele(vp); - VFS_UNLOCK_GIANT(locked); vp = NULL; pmclog_process_map_in(po, p->p_pid, start_addr, fullpath); diff --git a/sys/dev/md/md.c b/sys/dev/md/md.c index 2006099..60e80c9 100644 --- a/sys/dev/md/md.c +++ b/sys/dev/md/md.c @@ -506,7 +506,7 @@ mdstart_preload(struct md_s *sc, struct bio *bp) static int mdstart_vnode(struct md_s *sc, struct bio *bp) { - int error, vfslocked; + int error; struct uio auio; struct iovec aiov; struct mount *mp; @@ -534,13 +534,11 @@ mdstart_vnode(struct md_s *sc, struct bio *bp) */ if (bp->bio_cmd == BIO_FLUSH) { - vfslocked = VFS_LOCK_GIANT(vp->v_mount); (void) vn_start_write(vp, &mp, V_WAIT); vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); error = VOP_FSYNC(vp, MNT_WAIT, td); VOP_UNLOCK(vp, 0); vn_finished_write(mp); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -564,7 +562,6 @@ mdstart_vnode(struct md_s *sc, struct bio *bp) * When reading set IO_DIRECT to try to avoid double-caching * the data. When writing IO_DIRECT is not optimal. */ - vfslocked = VFS_LOCK_GIANT(vp->v_mount); if (bp->bio_cmd == BIO_READ) { vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); error = VOP_READ(vp, &auio, IO_DIRECT, sc->cred); @@ -577,7 +574,6 @@ mdstart_vnode(struct md_s *sc, struct bio *bp) VOP_UNLOCK(vp, 0); vn_finished_write(mp); } - VFS_UNLOCK_GIANT(vfslocked); bp->bio_resid = auio.uio_resid; return (error); } @@ -909,7 +905,7 @@ mdcreate_vnode(struct md_s *sc, struct md_ioctl *mdio, struct thread *td) { struct vattr vattr; struct nameidata nd; - int error, flags, vfslocked; + int error, flags; error = copyinstr(mdio->md_file, sc->file, sizeof(sc->file), NULL); if (error != 0) @@ -921,11 +917,10 @@ mdcreate_vnode(struct md_s *sc, struct md_ioctl *mdio, struct thread *td) */ if ((mdio->md_options & MD_READONLY) != 0) flags &= ~FWRITE; - NDINIT(&nd, LOOKUP, FOLLOW | MPSAFE, UIO_SYSSPACE, sc->file, td); + NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, sc->file, td); error = vn_open(&nd, &flags, 0, NULL); if (error != 0) return (error); - vfslocked = NDHASGIANT(&nd); NDFREE(&nd, NDF_ONLY_PNBUF); if (nd.ni_vp->v_type != VREG) { error = EINVAL; @@ -961,19 +956,16 @@ mdcreate_vnode(struct md_s *sc, struct md_ioctl *mdio, struct thread *td) nd.ni_vp->v_vflag &= ~VV_MD; goto bad; } - VFS_UNLOCK_GIANT(vfslocked); return (0); bad: VOP_UNLOCK(nd.ni_vp, 0); (void)vn_close(nd.ni_vp, flags, td->td_ucred, td); - VFS_UNLOCK_GIANT(vfslocked); return (error); } static int mddestroy(struct md_s *sc, struct thread *td) { - int vfslocked; if (sc->gp) { sc->gp->softc = NULL; @@ -995,13 +987,11 @@ mddestroy(struct md_s *sc, struct thread *td) mtx_unlock(&sc->queue_mtx); mtx_destroy(&sc->queue_mtx); if (sc->vnode != NULL) { - vfslocked = VFS_LOCK_GIANT(sc->vnode->v_mount); vn_lock(sc->vnode, LK_EXCLUSIVE | LK_RETRY); sc->vnode->v_vflag &= ~VV_MD; VOP_UNLOCK(sc->vnode, 0); (void)vn_close(sc->vnode, sc->flags & MD_READONLY ? FREAD : (FREAD|FWRITE), sc->cred, td); - VFS_UNLOCK_GIANT(vfslocked); } if (sc->cred != NULL) crfree(sc->cred); diff --git a/sys/fs/msdosfs/bootsect.h b/sys/fs/msdosfs/bootsect.h index 9e8aa97..ebd60a0 100644 --- a/sys/fs/msdosfs/bootsect.h +++ b/sys/fs/msdosfs/bootsect.h @@ -16,6 +16,8 @@ * * October 1992 */ +#ifndef _FS_MSDOSFS_BOOTSECT_H_ +#define _FS_MSDOSFS_BOOTSECT_H_ /* * Format of a boot sector. This is the first sector on a DOS floppy disk @@ -91,3 +93,5 @@ union bootsector { #define bsHiddenSecs bsBPB.bpbHiddenSecs #define bsHugeSectors bsBPB.bpbHugeSectors #endif + +#endif /* !_FS_MSDOSFS_BOOTSECT_H_ */ diff --git a/sys/fs/msdosfs/bpb.h b/sys/fs/msdosfs/bpb.h index addacd2..ce20f53 100644 --- a/sys/fs/msdosfs/bpb.h +++ b/sys/fs/msdosfs/bpb.h @@ -17,6 +17,9 @@ * October 1992 */ +#ifndef _FS_MSDOSFS_BPB_H_ +#define _FS_MSDOSFS_BPB_H_ + /* * BIOS Parameter Block (BPB) for DOS 3.3 */ @@ -78,7 +81,7 @@ struct bpb710 { u_int32_t bpbRootClust; /* start cluster for root directory */ u_int16_t bpbFSInfo; /* filesystem info structure sector */ u_int16_t bpbBackup; /* backup boot sector */ - /* There is a 12 byte filler here, but we ignore it */ + u_int8_t bpbReserved[12]; /* reserved for future expansion */ }; /* @@ -153,7 +156,7 @@ struct byte_bpb710 { u_int8_t bpbRootClust[4]; /* start cluster for root directory */ u_int8_t bpbFSInfo[2]; /* filesystem info structure sector */ u_int8_t bpbBackup[2]; /* backup boot sector */ - /* There is a 12 byte filler here, but we ignore it */ + u_int8_t bpbReserved[12]; /* reserved for future expansion */ }; /* @@ -168,3 +171,4 @@ struct fsinfo { u_int8_t fsifill2[12]; u_int8_t fsisig3[4]; }; +#endif /* !_FS_MSDOSFS_BPB_H_ */ diff --git a/sys/fs/msdosfs/direntry.h b/sys/fs/msdosfs/direntry.h index a55b0af..86b6fbb 100644 --- a/sys/fs/msdosfs/direntry.h +++ b/sys/fs/msdosfs/direntry.h @@ -47,16 +47,17 @@ * * October 1992 */ +#ifndef _FS_MSDOSFS_DIRENTRY_H_ +#define _FS_MSDOSFS_DIRENTRY_H_ /* * Structure of a dos directory entry. */ struct direntry { - u_int8_t deName[8]; /* filename, blank filled */ + u_int8_t deName[11]; /* filename, blank filled */ #define SLOT_EMPTY 0x00 /* slot has never been used */ #define SLOT_E5 0x05 /* the real value is 0xe5 */ #define SLOT_DELETED 0xe5 /* file in this slot deleted */ - u_int8_t deExtension[3]; /* extension, blank filled */ u_int8_t deAttributes; /* file attributes */ #define ATTR_NORMAL 0x00 /* normal file */ #define ATTR_READONLY 0x01 /* file is readonly */ @@ -155,7 +156,8 @@ int winChkName(struct mbnambuf *nbp, const u_char *un, size_t unlen, int chksum, struct msdosfsmount *pmp); int win2unixfn(struct mbnambuf *nbp, struct winentry *wep, int chksum, struct msdosfsmount *pmp); -u_int8_t winChksum(struct direntry *dep); +u_int8_t winChksum(u_int8_t *name); int winSlotCnt(const u_char *un, size_t unlen, struct msdosfsmount *pmp); size_t winLenFixup(const u_char *un, size_t unlen); #endif /* _KERNEL */ +#endif /* !_FS_MSDOSFS_DIRENTRY_H_ */ diff --git a/sys/fs/msdosfs/msdosfs_conv.c b/sys/fs/msdosfs/msdosfs_conv.c index 50dc1a0..8dc1d07 100644 --- a/sys/fs/msdosfs/msdosfs_conv.c +++ b/sys/fs/msdosfs/msdosfs_conv.c @@ -741,22 +741,13 @@ win2unixfn(nbp, wep, chksum, pmp) * Compute the unrolled checksum of a DOS filename for Win95 LFN use. */ u_int8_t -winChksum(struct direntry *dep) +winChksum(u_int8_t *name) { + int i; u_int8_t s; - s = dep->deName[0]; - s = ((s << 7) | (s >> 1)) + dep->deName[1]; - s = ((s << 7) | (s >> 1)) + dep->deName[2]; - s = ((s << 7) | (s >> 1)) + dep->deName[3]; - s = ((s << 7) | (s >> 1)) + dep->deName[4]; - s = ((s << 7) | (s >> 1)) + dep->deName[5]; - s = ((s << 7) | (s >> 1)) + dep->deName[6]; - s = ((s << 7) | (s >> 1)) + dep->deName[7]; - s = ((s << 7) | (s >> 1)) + dep->deExtension[0]; - s = ((s << 7) | (s >> 1)) + dep->deExtension[1]; - s = ((s << 7) | (s >> 1)) + dep->deExtension[2]; - + for (s = 0, i = 11; --i >= 0; s += *name++) + s = (s << 7)|(s >> 1); return (s); } diff --git a/sys/fs/msdosfs/msdosfs_lookup.c b/sys/fs/msdosfs/msdosfs_lookup.c index 1344f62..8e0c3d5 100644 --- a/sys/fs/msdosfs/msdosfs_lookup.c +++ b/sys/fs/msdosfs/msdosfs_lookup.c @@ -276,7 +276,7 @@ msdosfs_lookup(ap) /* * Check for a checksum or name match */ - chksum_ok = (chksum == winChksum(dep)); + chksum_ok = (chksum == winChksum(dep->deName)); if (!chksum_ok && (!olddos || bcmp(dosfilename, dep->deName, 11))) { chksum = -1; @@ -617,7 +617,7 @@ createde(dep, ddep, depp, cnp) * Now write the Win95 long name */ if (ddep->de_fndcnt > 0) { - u_int8_t chksum = winChksum(ndep); + u_int8_t chksum = winChksum(ndep->deName); const u_char *un = (const u_char *)cnp->cn_nameptr; int unlen = cnp->cn_namelen; int cnt = 1; diff --git a/sys/fs/msdosfs/msdosfs_vnops.c b/sys/fs/msdosfs/msdosfs_vnops.c index e62af02..e232f49 100644 --- a/sys/fs/msdosfs/msdosfs_vnops.c +++ b/sys/fs/msdosfs/msdosfs_vnops.c @@ -1287,7 +1287,7 @@ static struct { struct direntry dot; struct direntry dotdot; } dosdirtemplate = { - { ". ", " ", /* the . entry */ + { ". ", /* the . entry */ ATTR_DIRECTORY, /* file attribute */ 0, /* reserved */ 0, { 0, 0 }, { 0, 0 }, /* create time & date */ @@ -1297,7 +1297,7 @@ static struct { { 0, 0 }, /* startcluster */ { 0, 0, 0, 0 } /* filesize */ }, - { ".. ", " ", /* the .. entry */ + { ".. ", /* the .. entry */ ATTR_DIRECTORY, /* file attribute */ 0, /* reserved */ 0, { 0, 0 }, { 0, 0 }, /* create time & date */ @@ -1729,7 +1729,7 @@ msdosfs_readdir(ap) } else dirbuf.d_fileno = (uint32_t)fileno; - if (chksum != winChksum(dentp)) { + if (chksum != winChksum(dentp->deName)) { dirbuf.d_namlen = dos2unixfn(dentp->deName, (u_char *)dirbuf.d_name, dentp->deLowerCase | diff --git a/sys/fs/nfs/nfs_var.h b/sys/fs/nfs/nfs_var.h index 17714d7..592be4a 100644 --- a/sys/fs/nfs/nfs_var.h +++ b/sys/fs/nfs/nfs_var.h @@ -570,8 +570,6 @@ vnode_t nfsvno_getvp(fhandle_t *); int nfsvno_localconflict(vnode_t, int, u_int64_t, u_int64_t, struct nfslockconflict *, NFSPROC_T *); int nfsvno_advlock(vnode_t, int, u_int64_t, u_int64_t, NFSPROC_T *); -void nfsvno_unlockvfs(mount_t); -int nfsvno_lockvfs(mount_t); int nfsrv_v4rootexport(void *, struct ucred *, NFSPROC_T *); int nfsvno_testexp(struct nfsrv_descript *, struct nfsexstuff *); diff --git a/sys/fs/nfs/nfsdport.h b/sys/fs/nfs/nfsdport.h index 42dbe08..8f79a53 100644 --- a/sys/fs/nfs/nfsdport.h +++ b/sys/fs/nfs/nfsdport.h @@ -52,7 +52,6 @@ * needs to be returned by nfsd_fhtovp(). */ struct nfsexstuff { - int nes_vfslocked; /* required for all ports */ int nes_exflag; /* export flags */ int nes_numsecflavor; /* # of security flavors */ int nes_secflavors[MAXSECFLAVORS]; /* and the flavors */ diff --git a/sys/fs/nfsserver/nfs_nfsdport.c b/sys/fs/nfsserver/nfs_nfsdport.c index 3b7f8d0..7e2b955 100644 --- a/sys/fs/nfsserver/nfs_nfsdport.c +++ b/sys/fs/nfsserver/nfs_nfsdport.c @@ -319,18 +319,7 @@ nfsvno_namei(struct nfsrv_descript *nd, struct nameidata *ndp, * In either case ni_startdir will be dereferenced and NULLed * out. */ - if (exp->nes_vfslocked) - ndp->ni_cnd.cn_flags |= GIANTHELD; error = lookup(ndp); - /* - * The Giant lock should only change when - * crossing mount points. - */ - if (crossmnt) { - exp->nes_vfslocked = - (ndp->ni_cnd.cn_flags & GIANTHELD) != 0; - ndp->ni_cnd.cn_flags &= ~GIANTHELD; - } if (error) break; @@ -1922,8 +1911,7 @@ again: cn.cn_nameptr = dp->d_name; cn.cn_namelen = nlen; cn.cn_flags = ISLASTCN | - NOFOLLOW | LOCKLEAF | - MPSAFE; + NOFOLLOW | LOCKLEAF; if (nlen == 2 && dp->d_name[0] == '.' && dp->d_name[1] == '.') @@ -2482,19 +2470,6 @@ nfsvno_pathconf(struct vnode *vp, int flag, register_t *retf, * - get vp and export rights by calling nfsvno_fhtovp() * - if cred->cr_uid == 0 or MNT_EXPORTANON set it to credanon * for AUTH_SYS - * Also handle getting the Giant lock for the file system, - * as required: - * - if same mount point as *mpp - * do nothing - * else if *mpp == NULL - * if already locked - * leave it locked - * else - * call VFS_LOCK_GIANT() - * else - * if already locked - * unlock Giant - * call VFS_LOCK_GIANT() */ void nfsd_fhtovp(struct nfsrv_descript *nd, struct nfsrvfh *nfp, @@ -2513,23 +2488,10 @@ nfsd_fhtovp(struct nfsrv_descript *nd, struct nfsrvfh *nfp, if (!mp) { *vpp = NULL; nd->nd_repstat = ESTALE; - if (*mpp && exp->nes_vfslocked) - VFS_UNLOCK_GIANT(*mpp); *mpp = NULL; - exp->nes_vfslocked = 0; return; } - /* - * Now, handle Giant for the file system. - */ - if (*mpp != NULL && *mpp != mp && exp->nes_vfslocked) { - VFS_UNLOCK_GIANT(*mpp); - exp->nes_vfslocked = 0; - } - if (!exp->nes_vfslocked && *mpp != mp) - exp->nes_vfslocked = VFS_LOCK_GIANT(mp); - *mpp = mp; if (startwrite) vn_start_write(NULL, mpp, V_WAIT); @@ -2593,10 +2555,6 @@ nfsd_fhtovp(struct nfsrv_descript *nd, struct nfsrvfh *nfp, if (nd->nd_repstat) { if (startwrite) vn_finished_write(mp); - if (exp->nes_vfslocked) { - VFS_UNLOCK_GIANT(mp); - exp->nes_vfslocked = 0; - } vfs_rel(mp); *vpp = NULL; *mpp = NULL; @@ -2645,7 +2603,7 @@ nfsrv_v4rootexport(void *argp, struct ucred *cred, struct thread *p) /* * If fspec != NULL, this is the v4root path. */ - NDINIT(&nd, LOOKUP, FOLLOW | MPSAFE, UIO_USERSPACE, + NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, nfsexargp->fspec, p); if ((error = namei(&nd)) != 0) return (error); @@ -2855,29 +2813,6 @@ nfsvno_advlock(struct vnode *vp, int ftype, u_int64_t first, } /* - * Unlock an underlying local file system. - */ -void -nfsvno_unlockvfs(struct mount *mp) -{ - - VFS_UNLOCK_GIANT(mp); -} - -/* - * Lock an underlying file system, as required, and return - * whether or not it is locked. - */ -int -nfsvno_lockvfs(struct mount *mp) -{ - int ret; - - ret = VFS_LOCK_GIANT(mp); - return (ret); -} - -/* * Check the nfsv4 root exports. */ int diff --git a/sys/fs/nfsserver/nfs_nfsdserv.c b/sys/fs/nfsserver/nfs_nfsdserv.c index e56610b..9d2ffcf 100644 --- a/sys/fs/nfsserver/nfs_nfsdserv.c +++ b/sys/fs/nfsserver/nfs_nfsdserv.c @@ -1390,8 +1390,6 @@ nfsrvd_rename(struct nfsrv_descript *nd, int isdgram, return (error); } nd->nd_cred->cr_uid = nd->nd_saveduid; - /* Won't lock vfs if already locked, mp == NULL */ - tnes.nes_vfslocked = exp->nes_vfslocked; nfsd_fhtovp(nd, &tfh, &tdp, &tnes, &mp, 0, p); if (tdp) { tdirfor_ret = nfsvno_getattr(tdp, &tdirfor, nd->nd_cred, @@ -1404,12 +1402,8 @@ nfsrvd_rename(struct nfsrv_descript *nd, int isdgram, if (!nd->nd_repstat) { error = nfsrv_parsename(nd, tbufp, hashp, &tond.ni_pathlen); if (error) { - if (tdp) { - if (tnes.nes_vfslocked && !exp->nes_vfslocked && - !(nd->nd_flag & ND_NFSV4)) - nfsvno_unlockvfs(mp); + if (tdp) vrele(tdp); - } vput(dp); nfsvno_relpathbuf(&fromnd); nfsvno_relpathbuf(&tond); @@ -1423,12 +1417,8 @@ nfsrvd_rename(struct nfsrv_descript *nd, int isdgram, nfsrv_wcc(nd, tdirfor_ret, &tdirfor, tdiraft_ret, &tdiraft); } - if (tdp) { - if (tnes.nes_vfslocked && !exp->nes_vfslocked && - !(nd->nd_flag & ND_NFSV4)) - nfsvno_unlockvfs(mp); + if (tdp) vrele(tdp); - } vput(dp); nfsvno_relpathbuf(&fromnd); nfsvno_relpathbuf(&tond); @@ -1448,12 +1438,8 @@ nfsrvd_rename(struct nfsrv_descript *nd, int isdgram, } if (fdirp) vrele(fdirp); - if (tdp) { - if (tnes.nes_vfslocked && !exp->nes_vfslocked && - !(nd->nd_flag & ND_NFSV4)) - nfsvno_unlockvfs(mp); + if (tdp) vrele(tdp); - } nfsvno_relpathbuf(&tond); return (0); } @@ -1466,9 +1452,6 @@ nfsrvd_rename(struct nfsrv_descript *nd, int isdgram, fdiraft_ret = nfsvno_getattr(fdirp, &fdiraft, nd->nd_cred, p); if (tdirp) tdiraft_ret = nfsvno_getattr(tdirp, &tdiraft, nd->nd_cred, p); - if (tnes.nes_vfslocked && !exp->nes_vfslocked && - !(nd->nd_flag & ND_NFSV4)) - nfsvno_unlockvfs(mp); if (fdirp) vrele(fdirp); if (tdirp) @@ -1543,7 +1526,6 @@ nfsrvd_link(struct nfsrv_descript *nd, int isdgram, return (error); } /* Won't lock vfs if already locked, mp == NULL */ - tnes.nes_vfslocked = exp->nes_vfslocked; nfsd_fhtovp(nd, &dfh, &dp, &tnes, &mp, 0, p); if (dp) NFSVOPUNLOCK(dp, 0, p); @@ -1555,12 +1537,8 @@ nfsrvd_link(struct nfsrv_descript *nd, int isdgram, error = nfsrv_parsename(nd, bufp, hashp, &named.ni_pathlen); if (error) { vrele(vp); - if (dp) { - if (tnes.nes_vfslocked && !exp->nes_vfslocked && - !(nd->nd_flag & ND_NFSV4)) - nfsvno_unlockvfs(mp); + if (dp) vrele(dp); - } nfsvno_relpathbuf(&named); return (error); } @@ -1590,9 +1568,6 @@ nfsrvd_link(struct nfsrv_descript *nd, int isdgram, diraft_ret = nfsvno_getattr(dirp, &diraft, nd->nd_cred, p); vrele(dirp); } - if (tnes.nes_vfslocked && !exp->nes_vfslocked && - !(nd->nd_flag & ND_NFSV4)) - nfsvno_unlockvfs(mp); vrele(vp); if (nd->nd_flag & ND_NFSV3) { nfsrv_postopattr(nd, getret, &at); @@ -3114,7 +3089,6 @@ nfsrvd_secinfo(struct nfsrv_descript *nd, int isdgram, vp = named.ni_vp; nd->nd_repstat = nfsvno_getfh(vp, (fhandle_t *)fh.nfsrvfh_data, p); mp = vnode_mount(vp); /* so it won't try to re-lock filesys */ - retnes.nes_vfslocked = exp->nes_vfslocked; vput(vp); savflag = nd->nd_flag; if (!nd->nd_repstat) { diff --git a/sys/fs/nfsserver/nfs_nfsdsocket.c b/sys/fs/nfsserver/nfs_nfsdsocket.c index fc6e39e..32f1b92 100644 --- a/sys/fs/nfsserver/nfs_nfsdsocket.c +++ b/sys/fs/nfsserver/nfs_nfsdsocket.c @@ -383,7 +383,6 @@ nfsrvd_dorpc(struct nfsrv_descript *nd, int isdgram, nd->nd_repstat = NFSERR_GARBAGE; return; } - nes.nes_vfslocked = 0; if (nd->nd_flag & ND_PUBLOOKUP) nfsd_fhtovp(nd, &nfs_pubfh, &vp, &nes, &mp, nfs_writerpc[nd->nd_procnum], p); @@ -415,8 +414,6 @@ nfsrvd_dorpc(struct nfsrv_descript *nd, int isdgram, if (mp != NULL) { if (nfs_writerpc[nd->nd_procnum]) NFS_ENDWRITE(mp); - if (nes.nes_vfslocked) - nfsvno_unlockvfs(mp); } return; } @@ -445,8 +442,6 @@ nfsrvd_dorpc(struct nfsrv_descript *nd, int isdgram, if (mp) { if (nfs_writerpc[nd->nd_procnum]) NFS_ENDWRITE(mp); - if (nes.nes_vfslocked) - nfsvno_unlockvfs(mp); } NFSINCRGLOBAL(newnfsstats.srvrpccnt[nfsv3to4op[nd->nd_procnum]]); } @@ -596,7 +591,6 @@ nfsrvd_compound(struct nfsrv_descript *nd, int isdgram, } savevp = vp = NULL; - savevpnes.nes_vfslocked = vpnes.nes_vfslocked = 0; savemp = mp = NULL; NFSM_DISSECT(tl, u_int32_t *, NFSX_UNSIGNED); taglen = fxdr_unsigned(int, *tl); @@ -704,7 +698,6 @@ nfsrvd_compound(struct nfsrv_descript *nd, int isdgram, if (error) goto nfsmout; if (!nd->nd_repstat) { - nes.nes_vfslocked = vpnes.nes_vfslocked; nfsd_fhtovp(nd, &fh, &nvp, &nes, &mp, 0, p); } @@ -719,7 +712,6 @@ nfsrvd_compound(struct nfsrv_descript *nd, int isdgram, break; case NFSV4OP_PUTPUBFH: if (nfs_pubfhset) { - nes.nes_vfslocked = vpnes.nes_vfslocked; nfsd_fhtovp(nd, &nfs_pubfh, &nvp, &nes, &mp, 0, p); } else { @@ -735,7 +727,6 @@ nfsrvd_compound(struct nfsrv_descript *nd, int isdgram, break; case NFSV4OP_PUTROOTFH: if (nfs_rootfhset) { - nes.nes_vfslocked = vpnes.nes_vfslocked; nfsd_fhtovp(nd, &nfs_rootfh, &nvp, &nes, &mp, 0, p); if (!nd->nd_repstat) { @@ -746,15 +737,11 @@ nfsrvd_compound(struct nfsrv_descript *nd, int isdgram, vpnes = nes; } } else if (nfsv4root_vp && nfsv4root_set) { - if (vp) { - if (vpnes.nes_vfslocked) - nfsvno_unlockvfs(mp); + if (vp) vrele(vp); - } vp = nfsv4root_vp; VREF(vp); NFSVNO_SETEXRDONLY(&vpnes); - vpnes.nes_vfslocked = 0; mp = vnode_mount(vp); } else { nd->nd_repstat = NFSERR_NOFILEHANDLE; @@ -782,19 +769,6 @@ nfsrvd_compound(struct nfsrv_descript *nd, int isdgram, /* If vp == savevp, a no-op */ if (vp != savevp) { VREF(savevp); - if (mp == NULL || savemp == NULL) - panic("nfscmpmp"); - if (!savevpnes.nes_vfslocked && - vpnes.nes_vfslocked) { - if (mp == savemp) - panic("nfscmp2"); - nfsvno_unlockvfs(mp); - } else if (savevpnes.nes_vfslocked && - !vpnes.nes_vfslocked) { - if (mp == savemp) - panic("nfscmp3"); - savevpnes.nes_vfslocked = nfsvno_lockvfs(savemp); - } vrele(vp); vp = savevp; vpnes = savevpnes; @@ -860,10 +834,6 @@ nfsrvd_compound(struct nfsrv_descript *nd, int isdgram, NFSV4ROOT_FSID0 && vfs_statfs(vnode_mount(nvp))->f_fsid.val[1] == NFSV4ROOT_FSID1) { - if (vpnes.nes_vfslocked) { - nfsvno_unlockvfs(mp); - vpnes.nes_vfslocked = 0; - } NFSVNO_SETEXRDONLY(&vpnes); mp = vnode_mount(nvp); } else { @@ -875,12 +845,8 @@ nfsrvd_compound(struct nfsrv_descript *nd, int isdgram, if (credanon != NULL) crfree(credanon); if (!nd->nd_repstat) { - if (vpnes.nes_vfslocked) - nfsvno_unlockvfs(mp); mp = vnode_mount(nvp); vpnes = nes; - vpnes.nes_vfslocked = - nfsvno_lockvfs(mp); } } } @@ -971,8 +937,6 @@ nfsmout: } else { *retopsp = txdr_unsigned(retops); } - if (mp && vpnes.nes_vfslocked) - nfsvno_unlockvfs(mp); if (vp) vrele(vp); if (savevp) diff --git a/sys/fs/procfs/procfs_map.c b/sys/fs/procfs/procfs_map.c index 878e2d5..77bf7e4 100644 --- a/sys/fs/procfs/procfs_map.c +++ b/sys/fs/procfs/procfs_map.c @@ -84,7 +84,7 @@ procfs_doprocmap(PFS_FILL_ARGS) struct vnode *vp; char *fullpath, *freepath; struct uidinfo *uip; - int error, vfslocked; + int error; unsigned int last_timestamp; #ifdef COMPAT_IA32 int wrap32 = 0; @@ -189,9 +189,7 @@ procfs_doprocmap(PFS_FILL_ARGS) VM_OBJECT_UNLOCK(obj); if (vp != NULL) { vn_fullpath(td, vp, &fullpath, &freepath); - vfslocked = VFS_LOCK_GIANT(vp->v_mount); vrele(vp); - VFS_UNLOCK_GIANT(vfslocked); } } else { type = "none"; diff --git a/sys/fs/unionfs/union_subr.c b/sys/fs/unionfs/union_subr.c index 0791d2e..a9f1a2d 100644 --- a/sys/fs/unionfs/union_subr.c +++ b/sys/fs/unionfs/union_subr.c @@ -331,7 +331,6 @@ unionfs_nodeget_out: void unionfs_noderem(struct vnode *vp, struct thread *td) { - int vfslocked; int count; struct unionfs_node *unp, *unp_t1, *unp_t2; struct unionfs_node_hashhead *hd; @@ -363,20 +362,12 @@ unionfs_noderem(struct vnode *vp, struct thread *td) if (dvp != NULLVP && unp->un_hash.le_prev != NULL) unionfs_rem_cached_vnode(unp, dvp); - if (lvp != NULLVP) { - vfslocked = VFS_LOCK_GIANT(lvp->v_mount); + if (lvp != NULLVP) vrele(lvp); - VFS_UNLOCK_GIANT(vfslocked); - } - if (uvp != NULLVP) { - vfslocked = VFS_LOCK_GIANT(uvp->v_mount); + if (uvp != NULLVP) vrele(uvp); - VFS_UNLOCK_GIANT(vfslocked); - } if (dvp != NULLVP) { - vfslocked = VFS_LOCK_GIANT(dvp->v_mount); vrele(dvp); - VFS_UNLOCK_GIANT(vfslocked); unp->un_dvp = NULLVP; } if (unp->un_path != NULL) { diff --git a/sys/geom/geom_vfs.c b/sys/geom/geom_vfs.c index 9d01f40..5fe6b56 100644 --- a/sys/geom/geom_vfs.c +++ b/sys/geom/geom_vfs.c @@ -33,7 +33,6 @@ __FBSDID("$FreeBSD$"); #include #include #include -#include /* XXX Temporary for VFS_LOCK_GIANT */ #include #include @@ -69,7 +68,6 @@ static void g_vfs_done(struct bio *bip) { struct buf *bp; - int vfslocked; /* * Provider ('bio_to') could have withered away sometime @@ -93,9 +91,7 @@ g_vfs_done(struct bio *bip) bp->b_ioflags |= BIO_ERROR; bp->b_resid = bp->b_bcount - bip->bio_completed; g_destroy_bio(bip); - vfslocked = VFS_LOCK_GIANT(((struct mount *)NULL)); bufdone(bp); - VFS_UNLOCK_GIANT(vfslocked); } void @@ -103,7 +99,6 @@ g_vfs_strategy(struct bufobj *bo, struct buf *bp) { struct g_consumer *cp; struct bio *bip; - int vfslocked; cp = bo->bo_private; /* G_VALID_CONSUMER(cp); We likely lack topology lock */ @@ -114,9 +109,7 @@ g_vfs_strategy(struct bufobj *bo, struct buf *bp) if (cp->provider == NULL) { bp->b_error = ENXIO; bp->b_ioflags |= BIO_ERROR; - vfslocked = VFS_LOCK_GIANT(((struct mount *)NULL)); bufdone(bp); - VFS_UNLOCK_GIANT(vfslocked); return; } @@ -155,7 +148,6 @@ g_vfs_open(struct vnode *vp, struct g_consumer **cpp, const char *fsname, int wr struct g_provider *pp; struct g_consumer *cp; struct bufobj *bo; - int vfslocked; int error; g_topology_assert(); @@ -172,9 +164,7 @@ g_vfs_open(struct vnode *vp, struct g_consumer **cpp, const char *fsname, int wr g_wither_geom(gp, ENXIO); return (error); } - vfslocked = VFS_LOCK_GIANT(vp->v_mount); vnode_create_vobject(vp, pp->mediasize, curthread); - VFS_UNLOCK_GIANT(vfslocked); *cpp = cp; bo = &vp->v_bufobj; bo->bo_ops = g_vfs_bufops; diff --git a/sys/geom/journal/g_journal.c b/sys/geom/journal/g_journal.c index 16a26f1..ecb1862 100644 --- a/sys/geom/journal/g_journal.c +++ b/sys/geom/journal/g_journal.c @@ -2868,7 +2868,7 @@ g_journal_do_switch(struct g_class *classp) struct mount *mp; struct bintime bt; char *mountpoint; - int error, vfslocked; + int error; DROP_GIANT(); g_topology_lock(); @@ -2920,11 +2920,8 @@ g_journal_do_switch(struct g_class *classp) mountpoint = mp->mnt_stat.f_mntonname; - vfslocked = VFS_LOCK_GIANT(mp); - error = vn_start_write(NULL, &mp, V_WAIT); if (error != 0) { - VFS_UNLOCK_GIANT(vfslocked); GJ_DEBUG(0, "vn_start_write(%s) failed (error=%d).", mountpoint, error); goto next; @@ -2956,10 +2953,8 @@ g_journal_do_switch(struct g_class *classp) vn_finished_write(mp); - if (error != 0) { - VFS_UNLOCK_GIANT(vfslocked); + if (error != 0) goto next; - } /* * Send BIO_FLUSH before freezing the file system, so it can be @@ -2971,7 +2966,6 @@ g_journal_do_switch(struct g_class *classp) GJ_TIMER_START(1, &bt); error = vfs_write_suspend(mp); - VFS_UNLOCK_GIANT(vfslocked); GJ_TIMER_STOP(1, &bt, "Suspend time of %s", mountpoint); if (error != 0) { GJ_DEBUG(0, "Cannot suspend file system %s (error=%d).", diff --git a/sys/i386/ibcs2/ibcs2_misc.c b/sys/i386/ibcs2/ibcs2_misc.c index c537100..d845717 100644 --- a/sys/i386/ibcs2/ibcs2_misc.c +++ b/sys/i386/ibcs2/ibcs2_misc.c @@ -330,7 +330,7 @@ ibcs2_getdents(td, uap) struct iovec aiov; struct ibcs2_dirent idb; off_t off; /* true file offset */ - int buflen, error, eofflag, vfslocked; + int buflen, error, eofflag; u_long *cookies = NULL, *cookiep; int ncookies; #define BSD_DIRENT(cp) ((struct dirent *)(cp)) @@ -343,9 +343,7 @@ ibcs2_getdents(td, uap) return (EBADF); } vp = fp->f_vnode; - vfslocked = VFS_LOCK_GIANT(vp->v_mount); if (vp->v_type != VDIR) { /* XXX vnode readdir op should do this */ - VFS_UNLOCK_GIANT(vfslocked); fdrop(fp, td); return (EINVAL); } @@ -462,7 +460,6 @@ eof: td->td_retval[0] = uap->nbytes - resid; out: VOP_UNLOCK(vp, 0); - VFS_UNLOCK_GIANT(vfslocked); fdrop(fp, td); if (cookies) free(cookies, M_TEMP); @@ -488,7 +485,7 @@ ibcs2_read(td, uap) char name[14]; } idb; off_t off; /* true file offset */ - int buflen, error, eofflag, size, vfslocked; + int buflen, error, eofflag, size; u_long *cookies = NULL, *cookiep; int ncookies; @@ -503,9 +500,7 @@ ibcs2_read(td, uap) return (EBADF); } vp = fp->f_vnode; - vfslocked = VFS_LOCK_GIANT(vp->v_mount); if (vp->v_type != VDIR) { - VFS_UNLOCK_GIANT(vfslocked); fdrop(fp, td); return read(td, (struct read_args *)uap); } @@ -628,7 +623,6 @@ eof: td->td_retval[0] = uap->nbytes - resid; out: VOP_UNLOCK(vp, 0); - VFS_UNLOCK_GIANT(vfslocked); fdrop(fp, td); if (cookies) free(cookies, M_TEMP); diff --git a/sys/kern/imgact_elf.c b/sys/kern/imgact_elf.c index 56cd66f..42c0670 100644 --- a/sys/kern/imgact_elf.c +++ b/sys/kern/imgact_elf.c @@ -561,7 +561,7 @@ __elfN(load_file)(struct proc *p, const char *file, u_long *addr, vm_prot_t prot; u_long rbase; u_long base_addr = 0; - int vfslocked, error, i, numsegs; + int error, i, numsegs; tempdata = malloc(sizeof(*tempdata), M_TEMP, M_WAITOK); nd = &tempdata->nd; @@ -578,14 +578,11 @@ __elfN(load_file)(struct proc *p, const char *file, u_long *addr, imgp->object = NULL; imgp->execlabel = NULL; - NDINIT(nd, LOOKUP, MPSAFE|LOCKLEAF|FOLLOW, UIO_SYSSPACE, file, - curthread); - vfslocked = 0; + NDINIT(nd, LOOKUP, LOCKLEAF | FOLLOW, UIO_SYSSPACE, file, curthread); if ((error = namei(nd)) != 0) { nd->ni_vp = NULL; goto fail; } - vfslocked = NDHASGIANT(nd); NDFREE(nd, NDF_ONLY_PNBUF); imgp->vp = nd->ni_vp; @@ -671,7 +668,6 @@ fail: if (nd->ni_vp) vput(nd->ni_vp); - VFS_UNLOCK_GIANT(vfslocked); free(tempdata, M_TEMP); return (error); diff --git a/sys/kern/kern_acct.c b/sys/kern/kern_acct.c index 049600a..344d70d 100644 --- a/sys/kern/kern_acct.c +++ b/sys/kern/kern_acct.c @@ -196,7 +196,7 @@ int acct(struct thread *td, struct acct_args *uap) { struct nameidata nd; - int error, flags, vfslocked; + int error, flags; error = priv_check(td, PRIV_ACCT); if (error) @@ -207,30 +207,26 @@ acct(struct thread *td, struct acct_args *uap) * appending and make sure it's a 'normal'. */ if (uap->path != NULL) { - NDINIT(&nd, LOOKUP, NOFOLLOW | MPSAFE | AUDITVNODE1, + NDINIT(&nd, LOOKUP, NOFOLLOW | AUDITVNODE1, UIO_USERSPACE, uap->path, td); flags = FWRITE | O_APPEND; error = vn_open(&nd, &flags, 0, NULL); if (error) return (error); - vfslocked = NDHASGIANT(&nd); NDFREE(&nd, NDF_ONLY_PNBUF); #ifdef MAC error = mac_system_check_acct(td->td_ucred, nd.ni_vp); if (error) { VOP_UNLOCK(nd.ni_vp, 0); vn_close(nd.ni_vp, flags, td->td_ucred, td); - VFS_UNLOCK_GIANT(vfslocked); return (error); } #endif VOP_UNLOCK(nd.ni_vp, 0); if (nd.ni_vp->v_type != VREG) { vn_close(nd.ni_vp, flags, td->td_ucred, td); - VFS_UNLOCK_GIANT(vfslocked); return (EACCES); } - VFS_UNLOCK_GIANT(vfslocked); #ifdef MAC } else { error = mac_system_check_acct(td->td_ucred, NULL); @@ -252,11 +248,8 @@ acct(struct thread *td, struct acct_args *uap) * enabled. */ acct_suspended = 0; - if (acct_vp != NULL) { - vfslocked = VFS_LOCK_GIANT(acct_vp->v_mount); + if (acct_vp != NULL) error = acct_disable(td); - VFS_UNLOCK_GIANT(vfslocked); - } if (uap->path == NULL) { if (acct_state & ACCT_RUNNING) { acct_state |= ACCT_EXITREQ; @@ -284,9 +277,7 @@ acct(struct thread *td, struct acct_args *uap) error = kproc_create(acct_thread, NULL, NULL, 0, 0, "accounting"); if (error) { - vfslocked = VFS_LOCK_GIANT(acct_vp->v_mount); (void) vn_close(acct_vp, acct_flags, acct_cred, td); - VFS_UNLOCK_GIANT(vfslocked); crfree(acct_cred); acct_configured = 0; acct_vp = NULL; @@ -337,7 +328,7 @@ acct_process(struct thread *td) struct plimit *newlim, *oldlim; struct proc *p; struct rusage ru; - int t, ret, vfslocked; + int t, ret; /* * Lockless check of accounting condition before doing the hard @@ -433,11 +424,9 @@ acct_process(struct thread *td) /* * Write the accounting information to the file. */ - vfslocked = VFS_LOCK_GIANT(acct_vp->v_mount); ret = vn_rdwr(UIO_WRITE, acct_vp, (caddr_t)&acct, sizeof (acct), (off_t)0, UIO_SYSSPACE, IO_APPEND|IO_UNIT, acct_cred, NOCRED, NULL, td); - VFS_UNLOCK_GIANT(vfslocked); sx_sunlock(&acct_sx); return (ret); } @@ -554,7 +543,6 @@ static void acctwatch(void) { struct statfs sb; - int vfslocked; sx_assert(&acct_sx, SX_XLOCKED); @@ -572,10 +560,8 @@ acctwatch(void) * If our vnode is no longer valid, tear it down and signal the * accounting thread to die. */ - vfslocked = VFS_LOCK_GIANT(acct_vp->v_mount); if (acct_vp->v_type == VBAD) { (void) acct_disable(NULL); - VFS_UNLOCK_GIANT(vfslocked); acct_state |= ACCT_EXITREQ; return; } @@ -584,11 +570,8 @@ acctwatch(void) * Stopping here is better than continuing, maybe it will be VBAD * next time around. */ - if (VFS_STATFS(acct_vp->v_mount, &sb) < 0) { - VFS_UNLOCK_GIANT(vfslocked); + if (VFS_STATFS(acct_vp->v_mount, &sb) < 0) return; - } - VFS_UNLOCK_GIANT(vfslocked); if (acct_suspended) { if (sb.f_bavail > (int64_t)(acctresume * sb.f_blocks / 100)) { diff --git a/sys/kern/kern_alq.c b/sys/kern/kern_alq.c index a4ece79..1d3ef53 100644 --- a/sys/kern/kern_alq.c +++ b/sys/kern/kern_alq.c @@ -246,7 +246,6 @@ alq_doio(struct alq *alq) struct ale *alstart; int totlen; int iov; - int vfslocked; vp = alq->aq_vp; td = curthread; @@ -288,7 +287,6 @@ alq_doio(struct alq *alq) /* * Do all of the junk required to write now. */ - vfslocked = VFS_LOCK_GIANT(vp->v_mount); vn_start_write(vp, &mp, V_WAIT); vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); /* @@ -300,7 +298,6 @@ alq_doio(struct alq *alq) VOP_WRITE(vp, &auio, IO_UNIT | IO_APPEND, alq->aq_cred); VOP_UNLOCK(vp, 0); vn_finished_write(mp); - VFS_UNLOCK_GIANT(vfslocked); ALQ_LOCK(alq); alq->aq_flags &= ~AQ_FLUSHING; @@ -343,23 +340,21 @@ alq_open(struct alq **alqp, const char *file, struct ucred *cred, int cmode, char *bufp; int flags; int error; - int i, vfslocked; + int i; *alqp = NULL; td = curthread; - NDINIT(&nd, LOOKUP, NOFOLLOW | MPSAFE, UIO_SYSSPACE, file, td); + NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_SYSSPACE, file, td); flags = FWRITE | O_NOFOLLOW | O_CREAT; error = vn_open_cred(&nd, &flags, cmode, 0, cred, NULL); if (error) return (error); - vfslocked = NDHASGIANT(&nd); NDFREE(&nd, NDF_ONLY_PNBUF); /* We just unlock so we hold a reference */ VOP_UNLOCK(nd.ni_vp, 0); - VFS_UNLOCK_GIANT(vfslocked); alq = malloc(sizeof(*alq), M_ALD, M_WAITOK|M_ZERO); alq->aq_entbuf = malloc(count * size, M_ALD, M_WAITOK|M_ZERO); diff --git a/sys/kern/kern_ctf.c b/sys/kern/kern_ctf.c index 758ad81..f01fb24 100644 --- a/sys/kern/kern_ctf.c +++ b/sys/kern/kern_ctf.c @@ -69,7 +69,6 @@ link_elf_ctf_get(linker_file_t lf, linker_ctf_t *lc) int i; int nbytes; int resid; - int vfslocked; size_t sz; struct nameidata nd; struct thread *td = curthread; @@ -114,12 +113,11 @@ link_elf_ctf_get(linker_file_t lf, linker_ctf_t *lc) */ ef->ctfcnt = -1; - NDINIT(&nd, LOOKUP, FOLLOW | MPSAFE, UIO_SYSSPACE, lf->pathname, td); + NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, lf->pathname, td); flags = FREAD; error = vn_open(&nd, &flags, 0, NULL); if (error) return (error); - vfslocked = NDHASGIANT(&nd); NDFREE(&nd, NDF_ONLY_PNBUF); /* Allocate memory for the FLF header. */ @@ -305,7 +303,6 @@ link_elf_ctf_get(linker_file_t lf, linker_ctf_t *lc) out: VOP_UNLOCK(nd.ni_vp, 0); vn_close(nd.ni_vp, FREAD, td->td_ucred, td); - VFS_UNLOCK_GIANT(vfslocked); if (hdr != NULL) free(hdr, M_LINKER); diff --git a/sys/kern/kern_descrip.c b/sys/kern/kern_descrip.c index 676de65..f1839f5 100644 --- a/sys/kern/kern_descrip.c +++ b/sys/kern/kern_descrip.c @@ -420,11 +420,9 @@ kern_fcntl(struct thread *td, int fd, int cmd, intptr_t arg) char *pop; struct vnode *vp; int error, flg, tmp; - int vfslocked; u_int old, new; uint64_t bsize; - vfslocked = 0; error = 0; flg = F_POSIX; p = td->td_proc; @@ -580,7 +578,6 @@ kern_fcntl(struct thread *td, int fd, int cmd, intptr_t arg) fhold(fp); FILEDESC_SUNLOCK(fdp); vp = fp->f_vnode; - vfslocked = VFS_LOCK_GIANT(vp->v_mount); switch (flp->l_type) { case F_RDLCK: if ((fp->f_flag & FREAD) == 0) { @@ -624,8 +621,6 @@ kern_fcntl(struct thread *td, int fd, int cmd, intptr_t arg) error = EINVAL; break; } - VFS_UNLOCK_GIANT(vfslocked); - vfslocked = 0; /* Check for race with close */ FILEDESC_SLOCK(fdp); if ((unsigned) fd >= fdp->fd_nfiles || @@ -635,11 +630,8 @@ kern_fcntl(struct thread *td, int fd, int cmd, intptr_t arg) flp->l_start = 0; flp->l_len = 0; flp->l_type = F_UNLCK; - vfslocked = VFS_LOCK_GIANT(vp->v_mount); (void) VOP_ADVLOCK(vp, (caddr_t)p->p_leader, F_UNLCK, flp, F_POSIX); - VFS_UNLOCK_GIANT(vfslocked); - vfslocked = 0; } else FILEDESC_SUNLOCK(fdp); fdrop(fp, td); @@ -681,11 +673,8 @@ kern_fcntl(struct thread *td, int fd, int cmd, intptr_t arg) fhold(fp); FILEDESC_SUNLOCK(fdp); vp = fp->f_vnode; - vfslocked = VFS_LOCK_GIANT(vp->v_mount); error = VOP_ADVLOCK(vp, (caddr_t)p->p_leader, F_GETLK, flp, F_POSIX); - VFS_UNLOCK_GIANT(vfslocked); - vfslocked = 0; fdrop(fp, td); break; @@ -708,7 +697,6 @@ kern_fcntl(struct thread *td, int fd, int cmd, intptr_t arg) FILEDESC_SUNLOCK(fdp); if (arg != 0) { vp = fp->f_vnode; - vfslocked = VFS_LOCK_GIANT(vp->v_mount); error = vn_lock(vp, LK_SHARED); if (error != 0) goto readahead_vnlock_fail; @@ -719,9 +707,7 @@ kern_fcntl(struct thread *td, int fd, int cmd, intptr_t arg) new = old = fp->f_flag; new |= FRDAHEAD; } while (!atomic_cmpset_rel_int(&fp->f_flag, old, new)); -readahead_vnlock_fail: - VFS_UNLOCK_GIANT(vfslocked); - vfslocked = 0; + readahead_vnlock_fail:; } else { do { new = old = fp->f_flag; @@ -735,7 +721,6 @@ readahead_vnlock_fail: error = EINVAL; break; } - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -1332,12 +1317,9 @@ fpathconf(struct thread *td, struct fpathconf_args *uap) } vp = fp->f_vnode; if (vp != NULL) { - int vfslocked; - vfslocked = VFS_LOCK_GIANT(vp->v_mount); vn_lock(vp, LK_SHARED | LK_RETRY); error = VOP_PATHCONF(vp, uap->name, td->td_retval); VOP_UNLOCK(vp, 0); - VFS_UNLOCK_GIANT(vfslocked); } else if (fp->f_type == DTYPE_PIPE || fp->f_type == DTYPE_SOCKET) { if (uap->name != _PC_PIPE_BUF) { error = EINVAL; @@ -1727,7 +1709,7 @@ fdfree(struct thread *td) { struct filedesc *fdp; struct file **fpp; - int i, locked; + int i; struct filedesc_to_leader *fdtol; struct file *fp; struct vnode *cdir, *jdir, *rdir, *vp; @@ -1761,14 +1743,12 @@ fdfree(struct thread *td) lf.l_len = 0; lf.l_type = F_UNLCK; vp = fp->f_vnode; - locked = VFS_LOCK_GIANT(vp->v_mount); (void) VOP_ADVLOCK(vp, (caddr_t)td->td_proc-> p_leader, F_UNLCK, &lf, F_POSIX); - VFS_UNLOCK_GIANT(locked); FILEDESC_XLOCK(fdp); fdrop(fp, td); fpp = fdp->fd_ofiles + i; @@ -1848,21 +1828,12 @@ fdfree(struct thread *td) fdp->fd_jdir = NULL; FILEDESC_XUNLOCK(fdp); - if (cdir) { - locked = VFS_LOCK_GIANT(cdir->v_mount); + if (cdir) vrele(cdir); - VFS_UNLOCK_GIANT(locked); - } - if (rdir) { - locked = VFS_LOCK_GIANT(rdir->v_mount); + if (rdir) vrele(rdir); - VFS_UNLOCK_GIANT(locked); - } - if (jdir) { - locked = VFS_LOCK_GIANT(jdir->v_mount); + if (jdir) vrele(jdir); - VFS_UNLOCK_GIANT(locked); - } fddrop(fdp); } @@ -2066,10 +2037,7 @@ closef(struct file *fp, struct thread *td) * leaked. */ if (fp->f_type == DTYPE_VNODE && td != NULL) { - int vfslocked; - vp = fp->f_vnode; - vfslocked = VFS_LOCK_GIANT(vp->v_mount); if ((td->td_proc->p_leader->p_flag & P_ADVLOCK) != 0) { lf.l_whence = SEEK_SET; lf.l_start = 0; @@ -2112,7 +2080,6 @@ closef(struct file *fp, struct thread *td) } FILEDESC_XUNLOCK(fdp); } - VFS_UNLOCK_GIANT(vfslocked); } return (fdrop(fp, td)); } @@ -2378,7 +2345,6 @@ flock(struct thread *td, struct flock_args *uap) struct file *fp; struct vnode *vp; struct flock lf; - int vfslocked; int error; if ((error = fget(td, uap->fd, &fp)) != 0) @@ -2389,7 +2355,6 @@ flock(struct thread *td, struct flock_args *uap) } vp = fp->f_vnode; - vfslocked = VFS_LOCK_GIANT(vp->v_mount); lf.l_whence = SEEK_SET; lf.l_start = 0; lf.l_len = 0; @@ -2412,7 +2377,6 @@ flock(struct thread *td, struct flock_args *uap) (uap->how & LOCK_NB) ? F_FLOCK : F_FLOCK | F_WAIT); done2: fdrop(fp, td); - VFS_UNLOCK_GIANT(vfslocked); return (error); } /* @@ -2683,7 +2647,6 @@ export_vnode_for_osysctl(struct vnode *vp, int type, { int error; char *fullpath, *freepath; - int vfslocked; bzero(kif, sizeof(*kif)); kif->kf_structsize = sizeof(*kif); @@ -2709,9 +2672,7 @@ export_vnode_for_osysctl(struct vnode *vp, int type, fullpath = "-"; FILEDESC_SUNLOCK(fdp); vn_fullpath(curthread, vp, &fullpath, &freepath); - vfslocked = VFS_LOCK_GIANT(vp->v_mount); vrele(vp); - VFS_UNLOCK_GIANT(vfslocked); strlcpy(kif->kf_path, fullpath, sizeof(kif->kf_path)); if (freepath != NULL) free(freepath, M_TEMP); @@ -2735,7 +2696,6 @@ sysctl_kern_proc_ofiledesc(SYSCTL_HANDLER_ARGS) struct file *fp; struct proc *p; struct tty *tp; - int vfslocked; name = (int *)arg1; if ((p = pfind((pid_t)name[0])) == NULL) @@ -2878,9 +2838,7 @@ sysctl_kern_proc_ofiledesc(SYSCTL_HANDLER_ARGS) fullpath = "-"; FILEDESC_SUNLOCK(fdp); vn_fullpath(curthread, vp, &fullpath, &freepath); - vfslocked = VFS_LOCK_GIANT(vp->v_mount); vrele(vp); - VFS_UNLOCK_GIANT(vfslocked); strlcpy(kif->kf_path, fullpath, sizeof(kif->kf_path)); if (freepath != NULL) @@ -2933,7 +2891,6 @@ export_vnode_for_sysctl(struct vnode *vp, int type, { int error; char *fullpath, *freepath; - int vfslocked; bzero(kif, sizeof(*kif)); @@ -2958,9 +2915,7 @@ export_vnode_for_sysctl(struct vnode *vp, int type, fullpath = "-"; FILEDESC_SUNLOCK(fdp); vn_fullpath(curthread, vp, &fullpath, &freepath); - vfslocked = VFS_LOCK_GIANT(vp->v_mount); vrele(vp); - VFS_UNLOCK_GIANT(vfslocked); strlcpy(kif->kf_path, fullpath, sizeof(kif->kf_path)); if (freepath != NULL) free(freepath, M_TEMP); @@ -2988,7 +2943,6 @@ sysctl_kern_proc_filedesc(SYSCTL_HANDLER_ARGS) struct file *fp; struct proc *p; struct tty *tp; - int vfslocked; size_t oldidx; name = (int *)arg1; @@ -3131,9 +3085,7 @@ sysctl_kern_proc_filedesc(SYSCTL_HANDLER_ARGS) fullpath = "-"; FILEDESC_SUNLOCK(fdp); vn_fullpath(curthread, vp, &fullpath, &freepath); - vfslocked = VFS_LOCK_GIANT(vp->v_mount); vrele(vp); - VFS_UNLOCK_GIANT(vfslocked); strlcpy(kif->kf_path, fullpath, sizeof(kif->kf_path)); if (freepath != NULL) diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c index dce624d..746fbc1 100644 --- a/sys/kern/kern_exec.c +++ b/sys/kern/kern_exec.c @@ -338,7 +338,6 @@ do_execve(td, args, mac_p) #endif struct vnode *textvp = NULL, *binvp = NULL; int credential_changing; - int vfslocked; int textset; #ifdef MAC struct label *interpvplabel = NULL; @@ -349,7 +348,6 @@ do_execve(td, args, mac_p) #endif static const char fexecv_proc_title[] = "(fexecv)"; - vfslocked = 0; imgp = &image_params; /* @@ -403,7 +401,7 @@ do_execve(td, args, mac_p) */ if (args->fname != NULL) { NDINIT(&nd, LOOKUP, ISOPEN | LOCKLEAF | FOLLOW | SAVENAME - | MPSAFE | AUDITVNODE1, UIO_SYSSPACE, args->fname, td); + | AUDITVNODE1, UIO_SYSSPACE, args->fname, td); } SDT_PROBE(proc, kernel, , exec, args->fname, 0, 0, 0, 0 ); @@ -414,7 +412,6 @@ interpret: if (error) goto exec_fail; - vfslocked = NDHASGIANT(&nd); binvp = nd.ni_vp; imgp->vp = binvp; } else { @@ -422,7 +419,6 @@ interpret: error = fgetvp(td, args->fd, &binvp); if (error) goto exec_fail; - vfslocked = VFS_LOCK_GIANT(binvp->v_mount); vn_lock(binvp, LK_EXCLUSIVE | LK_RETRY); AUDIT_ARG_VNODE1(binvp); imgp->vp = binvp; @@ -511,10 +507,8 @@ interpret: vput(binvp); vm_object_deallocate(imgp->object); imgp->object = NULL; - VFS_UNLOCK_GIANT(vfslocked); - vfslocked = 0; /* set new name to that of the interpreter */ - NDINIT(&nd, LOOKUP, LOCKLEAF | FOLLOW | SAVENAME | MPSAFE, + NDINIT(&nd, LOOKUP, LOCKLEAF | FOLLOW | SAVENAME, UIO_SYSSPACE, imgp->interpreter_name, td); args->fname = imgp->interpreter_name; goto interpret; @@ -823,23 +817,13 @@ done1: /* * Handle deferred decrement of ref counts. */ - if (textvp != NULL) { - int tvfslocked; - - tvfslocked = VFS_LOCK_GIANT(textvp->v_mount); + if (textvp != NULL) vrele(textvp); - VFS_UNLOCK_GIANT(tvfslocked); - } if (binvp && error != 0) vrele(binvp); #ifdef KTRACE - if (tracevp != NULL) { - int tvfslocked; - - tvfslocked = VFS_LOCK_GIANT(tracevp->v_mount); + if (tracevp != NULL) vrele(tracevp); - VFS_UNLOCK_GIANT(tvfslocked); - } if (tracecred != NULL) crfree(tracecred); #endif @@ -892,7 +876,6 @@ done2: mac_execve_exit(imgp); mac_execve_interpreter_exit(interpvplabel); #endif - VFS_UNLOCK_GIANT(vfslocked); exec_free_args(args); if (error && imgp->vmspace_destroyed) { diff --git a/sys/kern/kern_exit.c b/sys/kern/kern_exit.c index af00f42..fa809fd 100644 --- a/sys/kern/kern_exit.c +++ b/sys/kern/kern_exit.c @@ -126,7 +126,6 @@ exit1(struct thread *td, int rv) struct ucred *tracecred; #endif struct plimit *plim; - int locked; mtx_assert(&Giant, MA_NOTOWNED); @@ -375,11 +374,8 @@ exit1(struct thread *td, int rv) p->p_tracecred = NULL; mtx_unlock(&ktrace_mtx); PROC_UNLOCK(p); - if (tracevp != NULL) { - locked = VFS_LOCK_GIANT(tracevp->v_mount); + if (tracevp != NULL) vrele(tracevp); - VFS_UNLOCK_GIANT(locked); - } if (tracecred != NULL) crfree(tracecred); } @@ -389,9 +385,7 @@ exit1(struct thread *td, int rv) */ if ((vtmp = p->p_textvp) != NULL) { p->p_textvp = NULL; - locked = VFS_LOCK_GIANT(vtmp->v_mount); vrele(vtmp); - VFS_UNLOCK_GIANT(locked); } /* diff --git a/sys/kern/kern_jail.c b/sys/kern/kern_jail.c index 93fdfa9..5428486 100644 --- a/sys/kern/kern_jail.c +++ b/sys/kern/kern_jail.c @@ -515,7 +515,7 @@ kern_jail_set(struct thread *td, struct uio *optuio, int flags) int created, cuflags, descend, enforce, error, errmsg_len, errmsg_pos; int gotchildmax, gotenforce, gothid, gotslevel; int fi, jid, jsys, len, level; - int childmax, slevel, vfslocked; + int childmax, slevel; #if defined(INET) || defined(INET6) int ii, ij; #endif @@ -888,21 +888,17 @@ kern_jail_set(struct thread *td, struct uio *optuio, int flags) error = ENAMETOOLONG; goto done_free; } - NDINIT(&nd, LOOKUP, MPSAFE | FOLLOW, UIO_SYSSPACE, - path, td); + NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, path, td); error = namei(&nd); if (error) goto done_free; - vfslocked = NDHASGIANT(&nd); root = nd.ni_vp; NDFREE(&nd, NDF_ONLY_PNBUF); if (root->v_type != VDIR) { error = ENOTDIR; vrele(root); - VFS_UNLOCK_GIANT(vfslocked); goto done_free; } - VFS_UNLOCK_GIANT(vfslocked); } } @@ -1754,11 +1750,8 @@ kern_jail_set(struct thread *td, struct uio *optuio, int flags) done_unlock_list: sx_xunlock(&allprison_lock); done_releroot: - if (root != NULL) { - vfslocked = VFS_LOCK_GIANT(root->v_mount); + if (root != NULL) vrele(root); - VFS_UNLOCK_GIANT(vfslocked); - } done_errmsg: if (error) { vfs_getopt(opts, "errmsg", (void **)&errmsg, &errmsg_len); @@ -2233,7 +2226,7 @@ do_jail_attach(struct thread *td, struct prison *pr) struct prison *ppr; struct proc *p; struct ucred *newcred, *oldcred; - int vfslocked, error; + int error; /* * XXX: Note that there is a slight race here if two threads @@ -2264,7 +2257,6 @@ do_jail_attach(struct thread *td, struct prison *pr) if (error) goto e_revert_osd; - vfslocked = VFS_LOCK_GIANT(pr->pr_root->v_mount); vn_lock(pr->pr_root, LK_EXCLUSIVE | LK_RETRY); if ((error = change_dir(pr->pr_root, td)) != 0) goto e_unlock; @@ -2274,8 +2266,7 @@ do_jail_attach(struct thread *td, struct prison *pr) #endif VOP_UNLOCK(pr->pr_root, 0); if ((error = change_root(pr->pr_root, td))) - goto e_unlock_giant; - VFS_UNLOCK_GIANT(vfslocked); + goto e_revert_osd; newcred = crget(); PROC_LOCK(p); @@ -2290,8 +2281,6 @@ do_jail_attach(struct thread *td, struct prison *pr) return (0); e_unlock: VOP_UNLOCK(pr->pr_root, 0); - e_unlock_giant: - VFS_UNLOCK_GIANT(vfslocked); e_revert_osd: /* Tell modules this thread is still in its old jail after all. */ (void)osd_jail_call(ppr, PR_METHOD_ATTACH, td); @@ -2440,7 +2429,6 @@ static void prison_deref(struct prison *pr, int flags) { struct prison *ppr, *tpr; - int vfslocked; if (!(flags & PD_LOCKED)) mtx_lock(&pr->pr_mtx); @@ -2502,11 +2490,8 @@ prison_deref(struct prison *pr, int flags) if (pr->pr_vnet != ppr->pr_vnet) vnet_destroy(pr->pr_vnet); #endif - if (pr->pr_root != NULL) { - vfslocked = VFS_LOCK_GIANT(pr->pr_root->v_mount); + if (pr->pr_root != NULL) vrele(pr->pr_root); - VFS_UNLOCK_GIANT(vfslocked); - } mtx_destroy(&pr->pr_mtx); #ifdef INET free(pr->pr_ip4, M_PRISON); diff --git a/sys/kern/kern_ktrace.c b/sys/kern/kern_ktrace.c index 2182ff7..a09ce45 100644 --- a/sys/kern/kern_ktrace.c +++ b/sys/kern/kern_ktrace.c @@ -647,7 +647,7 @@ ktrace(td, uap) int ops = KTROP(uap->ops); int descend = uap->ops & KTRFLAG_DESCEND; int nfound, ret = 0; - int flags, error = 0, vfslocked; + int flags, error = 0; struct nameidata nd; struct ucred *cred; @@ -662,25 +662,21 @@ ktrace(td, uap) /* * an operation which requires a file argument. */ - NDINIT(&nd, LOOKUP, NOFOLLOW | MPSAFE, UIO_USERSPACE, - uap->fname, td); + NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, uap->fname, td); flags = FREAD | FWRITE | O_NOFOLLOW; error = vn_open(&nd, &flags, 0, NULL); if (error) { ktrace_exit(td); return (error); } - vfslocked = NDHASGIANT(&nd); NDFREE(&nd, NDF_ONLY_PNBUF); vp = nd.ni_vp; VOP_UNLOCK(vp, 0); if (vp->v_type != VREG) { (void) vn_close(vp, FREAD|FWRITE, td->td_ucred, td); - VFS_UNLOCK_GIANT(vfslocked); ktrace_exit(td); return (EACCES); } - VFS_UNLOCK_GIANT(vfslocked); } /* * Clear all uses of the tracefile. @@ -709,10 +705,8 @@ ktrace(td, uap) } sx_sunlock(&allproc_lock); if (vrele_count > 0) { - vfslocked = VFS_LOCK_GIANT(vp->v_mount); while (vrele_count-- > 0) vrele(vp); - VFS_UNLOCK_GIANT(vfslocked); } goto done; } @@ -783,11 +777,8 @@ ktrace(td, uap) if (!ret) error = EPERM; done: - if (vp != NULL) { - vfslocked = VFS_LOCK_GIANT(vp->v_mount); + if (vp != NULL) (void) vn_close(vp, FWRITE, td->td_ucred, td); - VFS_UNLOCK_GIANT(vfslocked); - } ktrace_exit(td); return (error); #else /* !KTRACE */ @@ -877,13 +868,8 @@ ktrops(td, p, ops, facs, vp) } mtx_unlock(&ktrace_mtx); PROC_UNLOCK(p); - if (tracevp != NULL) { - int vfslocked; - - vfslocked = VFS_LOCK_GIANT(tracevp->v_mount); + if (tracevp != NULL) vrele(tracevp); - VFS_UNLOCK_GIANT(vfslocked); - } if (tracecred != NULL) crfree(tracecred); @@ -935,7 +921,7 @@ ktr_writerequest(struct thread *td, struct ktr_request *req) struct iovec aiov[3]; struct mount *mp; int datalen, buflen, vrele_count; - int error, vfslocked; + int error; /* * We hold the vnode and credential for use in I/O in case ktrace is @@ -993,7 +979,6 @@ ktr_writerequest(struct thread *td, struct ktr_request *req) auio.uio_iovcnt++; } - vfslocked = VFS_LOCK_GIANT(vp->v_mount); vn_start_write(vp, &mp, V_WAIT); vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); #ifdef MAC @@ -1006,10 +991,8 @@ ktr_writerequest(struct thread *td, struct ktr_request *req) crfree(cred); if (!error) { vrele(vp); - VFS_UNLOCK_GIANT(vfslocked); return; } - VFS_UNLOCK_GIANT(vfslocked); /* * If error encountered, give up tracing on this vnode. We defer @@ -1056,10 +1039,8 @@ ktr_writerequest(struct thread *td, struct ktr_request *req) * them but not yet committed them, as those are per-thread. The * thread will have to clear it itself on system call return. */ - vfslocked = VFS_LOCK_GIANT(vp->v_mount); while (vrele_count-- > 0) vrele(vp); - VFS_UNLOCK_GIANT(vfslocked); } /* diff --git a/sys/kern/kern_linker.c b/sys/kern/kern_linker.c index dd29302..463452b 100644 --- a/sys/kern/kern_linker.c +++ b/sys/kern/kern_linker.c @@ -1659,7 +1659,7 @@ linker_lookup_file(const char *path, int pathlen, const char *name, struct nameidata nd; struct thread *td = curthread; /* XXX */ char *result, **cpp, *sep; - int error, len, extlen, reclen, flags, vfslocked; + int error, len, extlen, reclen, flags; enum vtype type; extlen = 0; @@ -1680,18 +1680,16 @@ linker_lookup_file(const char *path, int pathlen, const char *name, * Attempt to open the file, and return the path if * we succeed and it's a regular file. */ - NDINIT(&nd, LOOKUP, FOLLOW | MPSAFE, UIO_SYSSPACE, result, td); + NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, result, td); flags = FREAD; error = vn_open(&nd, &flags, 0, NULL); if (error == 0) { - vfslocked = NDHASGIANT(&nd); NDFREE(&nd, NDF_ONLY_PNBUF); type = nd.ni_vp->v_type; if (vap) VOP_GETATTR(nd.ni_vp, vap, td->td_ucred); VOP_UNLOCK(nd.ni_vp, 0); vn_close(nd.ni_vp, FREAD, td->td_ucred, td); - VFS_UNLOCK_GIANT(vfslocked); if (type == VREG) return (result); } @@ -1719,7 +1717,6 @@ linker_hints_lookup(const char *path, int pathlen, const char *modname, u_char *hints = NULL; u_char *cp, *recptr, *bufend, *result, *best, *pathbuf, *sep; int error, ival, bestver, *intp, reclen, found, flags, clen, blen; - int vfslocked = 0; result = NULL; bestver = found = 0; @@ -1731,12 +1728,11 @@ linker_hints_lookup(const char *path, int pathlen, const char *modname, snprintf(pathbuf, reclen, "%.*s%s%s", pathlen, path, sep, linker_hintfile); - NDINIT(&nd, LOOKUP, NOFOLLOW | MPSAFE, UIO_SYSSPACE, pathbuf, td); + NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_SYSSPACE, pathbuf, td); flags = FREAD; error = vn_open(&nd, &flags, 0, NULL); if (error) goto bad; - vfslocked = NDHASGIANT(&nd); NDFREE(&nd, NDF_ONLY_PNBUF); if (nd.ni_vp->v_type != VREG) goto bad; @@ -1760,7 +1756,6 @@ linker_hints_lookup(const char *path, int pathlen, const char *modname, goto bad; VOP_UNLOCK(nd.ni_vp, 0); vn_close(nd.ni_vp, FREAD, cred, td); - VFS_UNLOCK_GIANT(vfslocked); nd.ni_vp = NULL; if (reclen != 0) { printf("can't read %d\n", reclen); @@ -1829,7 +1824,6 @@ bad: if (nd.ni_vp != NULL) { VOP_UNLOCK(nd.ni_vp, 0); vn_close(nd.ni_vp, FREAD, cred, td); - VFS_UNLOCK_GIANT(vfslocked); } /* * If nothing found or hints is absent - fallback to the old diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c index eaf13f2..252c8d1 100644 --- a/sys/kern/kern_proc.c +++ b/sys/kern/kern_proc.c @@ -1296,7 +1296,7 @@ sysctl_kern_proc_pathname(SYSCTL_HANDLER_ARGS) struct proc *p; struct vnode *vp; char *retbuf, *freebuf; - int error, vfslocked; + int error; if (arglen != 1) return (EINVAL); @@ -1322,9 +1322,7 @@ sysctl_kern_proc_pathname(SYSCTL_HANDLER_ARGS) if (*pidp != -1) PROC_UNLOCK(p); error = vn_fullpath(req->td, vp, &retbuf, &freebuf); - vfslocked = VFS_LOCK_GIANT(vp->v_mount); vrele(vp); - VFS_UNLOCK_GIANT(vfslocked); if (error) return (error); error = SYSCTL_OUT(req, retbuf, strlen(retbuf) + 1); @@ -1403,7 +1401,6 @@ sysctl_kern_proc_ovmmap(SYSCTL_HANDLER_ARGS) entry = entry->next) { vm_object_t obj, tobj, lobj; vm_offset_t addr; - int vfslocked; if (entry->eflags & MAP_ENTRY_IS_SUB_MAP) continue; @@ -1498,14 +1495,12 @@ sysctl_kern_proc_ovmmap(SYSCTL_HANDLER_ARGS) vn_fullpath(curthread, vp, &fullpath, &freepath); cred = curthread->td_ucred; - vfslocked = VFS_LOCK_GIANT(vp->v_mount); vn_lock(vp, LK_SHARED | LK_RETRY); if (VOP_GETATTR(vp, &va, cred) == 0) { kve->kve_fileid = va.va_fileid; kve->kve_fsid = va.va_fsid; } vput(vp); - VFS_UNLOCK_GIANT(vfslocked); } } else { kve->kve_type = KVME_TYPE_NONE; @@ -1579,7 +1574,6 @@ sysctl_kern_proc_vmmap(SYSCTL_HANDLER_ARGS) entry = entry->next) { vm_object_t obj, tobj, lobj; vm_offset_t addr; - int vfslocked; if (entry->eflags & MAP_ENTRY_IS_SUB_MAP) continue; @@ -1673,14 +1667,12 @@ sysctl_kern_proc_vmmap(SYSCTL_HANDLER_ARGS) vn_fullpath(curthread, vp, &fullpath, &freepath); cred = curthread->td_ucred; - vfslocked = VFS_LOCK_GIANT(vp->v_mount); vn_lock(vp, LK_SHARED | LK_RETRY); if (VOP_GETATTR(vp, &va, cred) == 0) { kve->kve_fileid = va.va_fileid; kve->kve_fsid = va.va_fsid; } vput(vp); - VFS_UNLOCK_GIANT(vfslocked); } } else { kve->kve_type = KVME_TYPE_NONE; diff --git a/sys/kern/kern_sig.c b/sys/kern/kern_sig.c index c0ec56f..1207494 100644 --- a/sys/kern/kern_sig.c +++ b/sys/kern/kern_sig.c @@ -3027,7 +3027,6 @@ coredump(struct thread *td) struct mount *mp; char *name; /* name of corefile */ off_t limit; - int vfslocked; PROC_LOCK_ASSERT(p, MA_OWNED); MPASS((p->p_flag & P_HADTHREADS) == 0 || p->p_singlethread == td); @@ -3069,7 +3068,7 @@ coredump(struct thread *td) } restart: - NDINIT(&nd, LOOKUP, NOFOLLOW | MPSAFE, UIO_SYSSPACE, name, td); + NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_SYSSPACE, name, td); flags = O_CREAT | FWRITE | O_NOFOLLOW; error = vn_open_cred(&nd, &flags, S_IRUSR | S_IWUSR, VN_OPEN_NOAUDIT, cred, NULL); @@ -3080,7 +3079,6 @@ restart: free(name, M_TEMP); return (error); } - vfslocked = NDHASGIANT(&nd); NDFREE(&nd, NDF_ONLY_PNBUF); vp = nd.ni_vp; @@ -3107,7 +3105,6 @@ restart: goto out; if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0) goto out; - VFS_UNLOCK_GIANT(vfslocked); goto restart; } @@ -3140,7 +3137,6 @@ out: audit_proc_coredump(td, name, error); #endif free(name, M_TEMP); - VFS_UNLOCK_GIANT(vfslocked); return (error); } diff --git a/sys/kern/link_elf.c b/sys/kern/link_elf.c index b389ace..6e3c5b8 100644 --- a/sys/kern/link_elf.c +++ b/sys/kern/link_elf.c @@ -657,17 +657,15 @@ link_elf_load_file(linker_class_t cls, const char* filename, int symstrindex; int symcnt; int strcnt; - int vfslocked; shdr = NULL; lf = NULL; - NDINIT(&nd, LOOKUP, FOLLOW | MPSAFE, UIO_SYSSPACE, filename, td); + NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, filename, td); flags = FREAD; error = vn_open(&nd, &flags, 0, NULL); if (error) return error; - vfslocked = NDHASGIANT(&nd); NDFREE(&nd, NDF_ONLY_PNBUF); if (nd.ni_vp->v_type != VREG) { error = ENOEXEC; @@ -975,7 +973,6 @@ out: free(firstpage, M_LINKER); VOP_UNLOCK(nd.ni_vp, 0); vn_close(nd.ni_vp, FREAD, td->td_ucred, td); - VFS_UNLOCK_GIANT(vfslocked); return error; } diff --git a/sys/kern/link_elf_obj.c b/sys/kern/link_elf_obj.c index 68c60d8..0097525 100644 --- a/sys/kern/link_elf_obj.c +++ b/sys/kern/link_elf_obj.c @@ -449,19 +449,17 @@ link_elf_load_file(linker_class_t cls, const char *filename, int nsym; int pb, rl, ra; int alignmask; - int vfslocked; shdr = NULL; lf = NULL; mapsize = 0; hdr = NULL; - NDINIT(&nd, LOOKUP, FOLLOW | MPSAFE, UIO_SYSSPACE, filename, td); + NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, filename, td); flags = FREAD; error = vn_open(&nd, &flags, 0, NULL); if (error) return error; - vfslocked = NDHASGIANT(&nd); NDFREE(&nd, NDF_ONLY_PNBUF); if (nd.ni_vp->v_type != VREG) { error = ENOEXEC; @@ -885,7 +883,6 @@ out: free(hdr, M_LINKER); VOP_UNLOCK(nd.ni_vp, 0); vn_close(nd.ni_vp, FREAD, td->td_ucred, td); - VFS_UNLOCK_GIANT(vfslocked); return error; } diff --git a/sys/kern/sys_process.c b/sys/kern/sys_process.c index 3fee0ed..3893511 100644 --- a/sys/kern/sys_process.c +++ b/sys/kern/sys_process.c @@ -371,7 +371,7 @@ ptrace_vm_entry(struct thread *td, struct proc *p, struct ptrace_vm_entry *pve) struct vnode *vp; char *freepath, *fullpath; u_int pathlen; - int error, index, vfslocked; + int error, index; error = 0; obj = NULL; @@ -445,14 +445,12 @@ ptrace_vm_entry(struct thread *td, struct proc *p, struct ptrace_vm_entry *pve) freepath = NULL; fullpath = NULL; vn_fullpath(td, vp, &fullpath, &freepath); - vfslocked = VFS_LOCK_GIANT(vp->v_mount); vn_lock(vp, LK_SHARED | LK_RETRY); if (VOP_GETATTR(vp, &vattr, td->td_ucred) == 0) { pve->pve_fileid = vattr.va_fileid; pve->pve_fsid = vattr.va_fsid; } vput(vp); - VFS_UNLOCK_GIANT(vfslocked); if (fullpath != NULL) { pve->pve_pathlen = strlen(fullpath) + 1; diff --git a/sys/kern/uipc_syscalls.c b/sys/kern/uipc_syscalls.c index a9001d9..1a4d811 100644 --- a/sys/kern/uipc_syscalls.c +++ b/sys/kern/uipc_syscalls.c @@ -1815,7 +1815,6 @@ kern_sendfile(struct thread *td, struct sendfile_args *uap, struct vm_page *pg; off_t off, xfsize, fsbytes = 0, sbytes = 0, rem = 0; int error, hdrlen = 0, mnw = 0; - int vfslocked; struct sendfile_sync *sfs = NULL; /* @@ -1827,7 +1826,6 @@ kern_sendfile(struct thread *td, struct sendfile_args *uap, AUDIT_ARG_FD(uap->fd); if ((error = fgetvp_read(td, uap->fd, &vp)) != 0) goto out; - vfslocked = VFS_LOCK_GIANT(vp->v_mount); vn_lock(vp, LK_SHARED | LK_RETRY); if (vp->v_type == VREG) { obj = vp->v_object; @@ -1849,7 +1847,6 @@ kern_sendfile(struct thread *td, struct sendfile_args *uap, } } VOP_UNLOCK(vp, 0); - VFS_UNLOCK_GIANT(vfslocked); if (obj == NULL) { error = EINVAL; goto out; @@ -2078,7 +2075,6 @@ retry_space: /* * Get the page from backing store. */ - vfslocked = VFS_LOCK_GIANT(vp->v_mount); error = vn_lock(vp, LK_SHARED); if (error != 0) goto after_read; @@ -2096,7 +2092,6 @@ retry_space: td->td_ucred, NOCRED, &resid, td); VOP_UNLOCK(vp, 0); after_read: - VFS_UNLOCK_GIANT(vfslocked); VM_OBJECT_LOCK(obj); vm_page_io_finish(pg); if (!error) @@ -2245,11 +2240,8 @@ out: } if (obj != NULL) vm_object_deallocate(obj); - if (vp != NULL) { - vfslocked = VFS_LOCK_GIANT(vp->v_mount); + if (vp != NULL) vrele(vp); - VFS_UNLOCK_GIANT(vfslocked); - } if (so) fdrop(sock_fp, td); if (m) diff --git a/sys/kern/uipc_usrreq.c b/sys/kern/uipc_usrreq.c index fdf3d90..4e172c6 100644 --- a/sys/kern/uipc_usrreq.c +++ b/sys/kern/uipc_usrreq.c @@ -427,7 +427,7 @@ uipc_bind(struct socket *so, struct sockaddr *nam, struct thread *td) { struct sockaddr_un *soun = (struct sockaddr_un *)nam; struct vattr vattr; - int error, namelen, vfslocked; + int error, namelen; struct nameidata nd; struct unpcb *unp; struct vnode *vp; @@ -467,15 +467,13 @@ uipc_bind(struct socket *so, struct sockaddr *nam, struct thread *td) buf[namelen] = 0; restart: - vfslocked = 0; - NDINIT(&nd, CREATE, MPSAFE | NOFOLLOW | LOCKPARENT | SAVENAME, + NDINIT(&nd, CREATE, NOFOLLOW | LOCKPARENT | SAVENAME, UIO_SYSSPACE, buf, td); /* SHOULD BE ABLE TO ADOPT EXISTING AND wakeup() ALA FIFO's */ error = namei(&nd); if (error) goto error; vp = nd.ni_vp; - vfslocked = NDHASGIANT(&nd); if (vp != NULL || vn_start_write(nd.ni_dvp, &mp, V_NOWAIT) != 0) { NDFREE(&nd, NDF_ONLY_PNBUF); if (nd.ni_dvp == vp) @@ -490,7 +488,6 @@ restart: error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH); if (error) goto error; - VFS_UNLOCK_GIANT(vfslocked); goto restart; } VATTR_NULL(&vattr); @@ -522,12 +519,10 @@ restart: UNP_LINK_WUNLOCK(); VOP_UNLOCK(vp, 0); vn_finished_write(mp); - VFS_UNLOCK_GIANT(vfslocked); free(buf, M_TEMP); return (0); error: - VFS_UNLOCK_GIANT(vfslocked); UNP_PCB_LOCK(unp); unp->unp_flags &= ~UNP_BINDING; UNP_PCB_UNLOCK(unp); @@ -645,13 +640,8 @@ uipc_detach(struct socket *so) uma_zfree(unp_zone, unp); } else UNP_PCB_UNLOCK(unp); - if (vp) { - int vfslocked; - - vfslocked = VFS_LOCK_GIANT(vp->v_mount); + if (vp) vrele(vp); - VFS_UNLOCK_GIANT(vfslocked); - } if (local_unp_rights) taskqueue_enqueue(taskqueue_thread, &unp_gc_task); } @@ -1214,7 +1204,7 @@ unp_connect(struct socket *so, struct sockaddr *nam, struct thread *td) struct vnode *vp; struct socket *so2, *so3; struct unpcb *unp, *unp2, *unp3; - int error, len, vfslocked; + int error, len; struct nameidata nd; char buf[SOCK_MAXADDRLEN]; struct sockaddr *sa; @@ -1240,7 +1230,7 @@ unp_connect(struct socket *so, struct sockaddr *nam, struct thread *td) UNP_PCB_UNLOCK(unp); sa = malloc(sizeof(struct sockaddr_un), M_SONAME, M_WAITOK); - NDINIT(&nd, LOOKUP, MPSAFE | FOLLOW | LOCKLEAF, UIO_SYSSPACE, buf, + NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, buf, td); error = namei(&nd); if (error) @@ -1248,7 +1238,6 @@ unp_connect(struct socket *so, struct sockaddr *nam, struct thread *td) else vp = nd.ni_vp; ASSERT_VOP_LOCKED(vp, "unp_connect"); - vfslocked = NDHASGIANT(&nd); NDFREE(&nd, NDF_ONLY_PNBUF); if (error) goto bad; @@ -1265,7 +1254,6 @@ unp_connect(struct socket *so, struct sockaddr *nam, struct thread *td) error = VOP_ACCESS(vp, VWRITE, td->td_ucred, td); if (error) goto bad; - VFS_UNLOCK_GIANT(vfslocked); unp = sotounpcb(so); KASSERT(unp != NULL, ("unp_connect: unp == NULL")); @@ -1346,16 +1334,9 @@ unp_connect(struct socket *so, struct sockaddr *nam, struct thread *td) UNP_PCB_UNLOCK(unp); bad2: UNP_LINK_WUNLOCK(); - if (vfslocked) - /* - * Giant has been previously acquired. This means filesystem - * isn't MPSAFE. Do it once again. - */ - mtx_lock(&Giant); bad: if (vp != NULL) vput(vp); - VFS_UNLOCK_GIANT(vfslocked); free(sa, M_SONAME); UNP_LINK_WLOCK(); UNP_PCB_LOCK(unp); diff --git a/sys/kern/vfs_acl.c b/sys/kern/vfs_acl.c index c44bb25..6455227 100644 --- a/sys/kern/vfs_acl.c +++ b/sys/kern/vfs_acl.c @@ -326,16 +326,14 @@ int __acl_get_file(struct thread *td, struct __acl_get_file_args *uap) { struct nameidata nd; - int vfslocked, error; + int error; - NDINIT(&nd, LOOKUP, MPSAFE|FOLLOW, UIO_USERSPACE, uap->path, td); + NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, uap->path, td); error = namei(&nd); - vfslocked = NDHASGIANT(&nd); if (error == 0) { error = vacl_get_acl(td, nd.ni_vp, uap->type, uap->aclp); NDFREE(&nd, 0); } - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -346,16 +344,14 @@ int __acl_get_link(struct thread *td, struct __acl_get_link_args *uap) { struct nameidata nd; - int vfslocked, error; + int error; - NDINIT(&nd, LOOKUP, MPSAFE|NOFOLLOW, UIO_USERSPACE, uap->path, td); + NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, uap->path, td); error = namei(&nd); - vfslocked = NDHASGIANT(&nd); if (error == 0) { error = vacl_get_acl(td, nd.ni_vp, uap->type, uap->aclp); NDFREE(&nd, 0); } - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -366,16 +362,14 @@ int __acl_set_file(struct thread *td, struct __acl_set_file_args *uap) { struct nameidata nd; - int vfslocked, error; + int error; - NDINIT(&nd, LOOKUP, MPSAFE|FOLLOW, UIO_USERSPACE, uap->path, td); + NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, uap->path, td); error = namei(&nd); - vfslocked = NDHASGIANT(&nd); if (error == 0) { error = vacl_set_acl(td, nd.ni_vp, uap->type, uap->aclp); NDFREE(&nd, 0); } - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -386,16 +380,14 @@ int __acl_set_link(struct thread *td, struct __acl_set_link_args *uap) { struct nameidata nd; - int vfslocked, error; + int error; - NDINIT(&nd, LOOKUP, MPSAFE|NOFOLLOW, UIO_USERSPACE, uap->path, td); + NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, uap->path, td); error = namei(&nd); - vfslocked = NDHASGIANT(&nd); if (error == 0) { error = vacl_set_acl(td, nd.ni_vp, uap->type, uap->aclp); NDFREE(&nd, 0); } - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -406,14 +398,12 @@ int __acl_get_fd(struct thread *td, struct __acl_get_fd_args *uap) { struct file *fp; - int vfslocked, error; + int error; error = getvnode(td->td_proc->p_fd, uap->filedes, &fp); if (error == 0) { - vfslocked = VFS_LOCK_GIANT(fp->f_vnode->v_mount); error = vacl_get_acl(td, fp->f_vnode, uap->type, uap->aclp); fdrop(fp, td); - VFS_UNLOCK_GIANT(vfslocked); } return (error); } @@ -425,14 +415,12 @@ int __acl_set_fd(struct thread *td, struct __acl_set_fd_args *uap) { struct file *fp; - int vfslocked, error; + int error; error = getvnode(td->td_proc->p_fd, uap->filedes, &fp); if (error == 0) { - vfslocked = VFS_LOCK_GIANT(fp->f_vnode->v_mount); error = vacl_set_acl(td, fp->f_vnode, uap->type, uap->aclp); fdrop(fp, td); - VFS_UNLOCK_GIANT(vfslocked); } return (error); } @@ -444,16 +432,14 @@ int __acl_delete_file(struct thread *td, struct __acl_delete_file_args *uap) { struct nameidata nd; - int vfslocked, error; + int error; - NDINIT(&nd, LOOKUP, MPSAFE|FOLLOW, UIO_USERSPACE, uap->path, td); + NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, uap->path, td); error = namei(&nd); - vfslocked = NDHASGIANT(&nd); if (error == 0) { error = vacl_delete(td, nd.ni_vp, uap->type); NDFREE(&nd, 0); } - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -464,16 +450,14 @@ int __acl_delete_link(struct thread *td, struct __acl_delete_link_args *uap) { struct nameidata nd; - int vfslocked, error; + int error; - NDINIT(&nd, LOOKUP, MPSAFE|NOFOLLOW, UIO_USERSPACE, uap->path, td); + NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, uap->path, td); error = namei(&nd); - vfslocked = NDHASGIANT(&nd); if (error == 0) { error = vacl_delete(td, nd.ni_vp, uap->type); NDFREE(&nd, 0); } - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -484,14 +468,12 @@ int __acl_delete_fd(struct thread *td, struct __acl_delete_fd_args *uap) { struct file *fp; - int vfslocked, error; + int error; error = getvnode(td->td_proc->p_fd, uap->filedes, &fp); if (error == 0) { - vfslocked = VFS_LOCK_GIANT(fp->f_vnode->v_mount); error = vacl_delete(td, fp->f_vnode, uap->type); fdrop(fp, td); - VFS_UNLOCK_GIANT(vfslocked); } return (error); } @@ -503,16 +485,14 @@ int __acl_aclcheck_file(struct thread *td, struct __acl_aclcheck_file_args *uap) { struct nameidata nd; - int vfslocked, error; + int error; - NDINIT(&nd, LOOKUP, MPSAFE|FOLLOW, UIO_USERSPACE, uap->path, td); + NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, uap->path, td); error = namei(&nd); - vfslocked = NDHASGIANT(&nd); if (error == 0) { error = vacl_aclcheck(td, nd.ni_vp, uap->type, uap->aclp); NDFREE(&nd, 0); } - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -523,16 +503,14 @@ int __acl_aclcheck_link(struct thread *td, struct __acl_aclcheck_link_args *uap) { struct nameidata nd; - int vfslocked, error; + int error; - NDINIT(&nd, LOOKUP, MPSAFE|NOFOLLOW, UIO_USERSPACE, uap->path, td); + NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_USERSPACE, uap->path, td); error = namei(&nd); - vfslocked = NDHASGIANT(&nd); if (error == 0) { error = vacl_aclcheck(td, nd.ni_vp, uap->type, uap->aclp); NDFREE(&nd, 0); } - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -543,14 +521,12 @@ int __acl_aclcheck_fd(struct thread *td, struct __acl_aclcheck_fd_args *uap) { struct file *fp; - int vfslocked, error; + int error; error = getvnode(td->td_proc->p_fd, uap->filedes, &fp); if (error == 0) { - vfslocked = VFS_LOCK_GIANT(fp->f_vnode->v_mount); error = vacl_aclcheck(td, fp->f_vnode, uap->type, uap->aclp); fdrop(fp, td); - VFS_UNLOCK_GIANT(vfslocked); } return (error); } diff --git a/sys/kern/vfs_aio.c b/sys/kern/vfs_aio.c index 088e4f6..5957a8d 100644 --- a/sys/kern/vfs_aio.c +++ b/sys/kern/vfs_aio.c @@ -785,10 +785,8 @@ static int aio_fsync_vnode(struct thread *td, struct vnode *vp) { struct mount *mp; - int vfslocked; int error; - vfslocked = VFS_LOCK_GIANT(vp->v_mount); if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0) goto drop; vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); @@ -802,7 +800,6 @@ aio_fsync_vnode(struct thread *td, struct vnode *vp) VOP_UNLOCK(vp, 0); vn_finished_write(mp); drop: - VFS_UNLOCK_GIANT(vfslocked); return (error); } diff --git a/sys/kern/vfs_bio.c b/sys/kern/vfs_bio.c index df9a257..feb8837 100644 --- a/sys/kern/vfs_bio.c +++ b/sys/kern/vfs_bio.c @@ -259,14 +259,13 @@ static struct mtx nblock; /* * Definitions for the buffer free lists. */ -#define BUFFER_QUEUES 6 /* number of free buffer queues */ +#define BUFFER_QUEUES 5 /* number of free buffer queues */ #define QUEUE_NONE 0 /* on no queue */ #define QUEUE_CLEAN 1 /* non-B_DELWRI buffers */ #define QUEUE_DIRTY 2 /* B_DELWRI buffers */ -#define QUEUE_DIRTY_GIANT 3 /* B_DELWRI buffers that need giant */ -#define QUEUE_EMPTYKVA 4 /* empty buffer headers w/KVA assignment */ -#define QUEUE_EMPTY 5 /* empty buffer headers */ +#define QUEUE_EMPTYKVA 3 /* empty buffer headers w/KVA assignment */ +#define QUEUE_EMPTY 4 /* empty buffer headers */ #define QUEUE_SENTINEL 1024 /* not an queue index, but mark for sentinel */ /* Queues for free buffers with various properties */ @@ -1413,10 +1412,7 @@ brelse(struct buf *bp) TAILQ_INSERT_HEAD(&bufqueues[QUEUE_CLEAN], bp, b_freelist); /* remaining buffers */ } else { - if ((bp->b_flags & (B_DELWRI|B_NEEDSGIANT)) == - (B_DELWRI|B_NEEDSGIANT)) - bp->b_qindex = QUEUE_DIRTY_GIANT; - else if (bp->b_flags & B_DELWRI) + if (bp->b_flags & B_DELWRI) bp->b_qindex = QUEUE_DIRTY; else bp->b_qindex = QUEUE_CLEAN; @@ -1493,10 +1489,7 @@ bqrelse(struct buf *bp) panic("bqrelse: free buffer onto another queue???"); /* buffers with stale but valid contents */ if (bp->b_flags & B_DELWRI) { - if (bp->b_flags & B_NEEDSGIANT) - bp->b_qindex = QUEUE_DIRTY_GIANT; - else - bp->b_qindex = QUEUE_DIRTY; + bp->b_qindex = QUEUE_DIRTY; TAILQ_INSERT_TAIL(&bufqueues[bp->b_qindex], bp, b_freelist); } else { /* @@ -2094,12 +2087,6 @@ buf_do_flush(struct vnode *vp) int flushed; flushed = flushbufqueues(vp, QUEUE_DIRTY, 0); - /* The list empty check here is slightly racy */ - if (!TAILQ_EMPTY(&bufqueues[QUEUE_DIRTY_GIANT])) { - mtx_lock(&Giant); - flushed += flushbufqueues(vp, QUEUE_DIRTY_GIANT, 0); - mtx_unlock(&Giant); - } if (flushed == 0) { /* * Could not find any buffers without rollback @@ -2107,12 +2094,6 @@ buf_do_flush(struct vnode *vp) * in the hopes of eventually making progress. */ flushbufqueues(vp, QUEUE_DIRTY, 1); - if (!TAILQ_EMPTY( - &bufqueues[QUEUE_DIRTY_GIANT])) { - mtx_lock(&Giant); - flushbufqueues(vp, QUEUE_DIRTY_GIANT, 1); - mtx_unlock(&Giant); - } } return (flushed); } diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c index 7854803..a327aef 100644 --- a/sys/kern/vfs_cache.c +++ b/sys/kern/vfs_cache.c @@ -918,7 +918,7 @@ kern___getcwd(struct thread *td, u_char *buf, enum uio_seg bufseg, u_int buflen) char *bp, *tmpbuf; struct filedesc *fdp; struct vnode *cdir, *rdir; - int error, vfslocked; + int error; if (disablecwd) return (ENODEV); @@ -936,12 +936,8 @@ kern___getcwd(struct thread *td, u_char *buf, enum uio_seg bufseg, u_int buflen) VREF(rdir); FILEDESC_SUNLOCK(fdp); error = vn_fullpath1(td, cdir, rdir, tmpbuf, &bp, buflen); - vfslocked = VFS_LOCK_GIANT(rdir->v_mount); vrele(rdir); - VFS_UNLOCK_GIANT(vfslocked); - vfslocked = VFS_LOCK_GIANT(cdir->v_mount); vrele(cdir); - VFS_UNLOCK_GIANT(vfslocked); if (!error) { if (bufseg == UIO_SYSSPACE) @@ -987,7 +983,7 @@ vn_fullpath(struct thread *td, struct vnode *vn, char **retbuf, char **freebuf) char *buf; struct filedesc *fdp; struct vnode *rdir; - int error, vfslocked; + int error; if (disablefullpath) return (ENODEV); @@ -1001,9 +997,7 @@ vn_fullpath(struct thread *td, struct vnode *vn, char **retbuf, char **freebuf) VREF(rdir); FILEDESC_SUNLOCK(fdp); error = vn_fullpath1(td, vn, rdir, buf, retbuf, MAXPATHLEN); - vfslocked = VFS_LOCK_GIANT(rdir->v_mount); vrele(rdir); - VFS_UNLOCK_GIANT(vfslocked); if (!error) *freebuf = buf; @@ -1064,7 +1058,7 @@ vn_vptocnp_locked(struct vnode **vp, struct ucred *cred, char *buf, { struct vnode *dvp; struct namecache *ncp; - int error, vfslocked; + int error; TAILQ_FOREACH(ncp, &((*vp)->v_cache_dst), nc_dst) { if ((ncp->nc_flag & NCF_ISDOTDOT) == 0) @@ -1090,12 +1084,10 @@ vn_vptocnp_locked(struct vnode **vp, struct ucred *cred, char *buf, vhold(*vp); CACHE_RUNLOCK(); - vfslocked = VFS_LOCK_GIANT((*vp)->v_mount); vn_lock(*vp, LK_SHARED | LK_RETRY); error = VOP_VPTOCNP(*vp, &dvp, cred, buf, buflen); VOP_UNLOCK(*vp, 0); vdrop(*vp); - VFS_UNLOCK_GIANT(vfslocked); if (error) { numfullpathfail2++; SDT_PROBE(vfs, namecache, fullpath, return, error, vp, diff --git a/sys/kern/vfs_extattr.c b/sys/kern/vfs_extattr.c index e7bf2d1..2e5fe78 100644 --- a/sys/kern/vfs_extattr.c +++ b/sys/kern/vfs_extattr.c @@ -68,7 +68,7 @@ extattrctl(td, uap) struct nameidata nd; struct mount *mp, *mp_writable; char attrname[EXTATTR_MAXNAMELEN]; - int vfslocked, fnvfslocked, error; + int error; AUDIT_ARG_CMD(uap->cmd); AUDIT_ARG_VALUE(uap->attrnamespace); @@ -84,27 +84,24 @@ extattrctl(td, uap) } AUDIT_ARG_TEXT(attrname); - vfslocked = fnvfslocked = 0; mp = NULL; filename_vp = NULL; if (uap->filename != NULL) { - NDINIT(&nd, LOOKUP, MPSAFE | FOLLOW | AUDITVNODE2, + NDINIT(&nd, LOOKUP, FOLLOW | AUDITVNODE2, UIO_USERSPACE, uap->filename, td); error = namei(&nd); if (error) return (error); - fnvfslocked = NDHASGIANT(&nd); filename_vp = nd.ni_vp; NDFREE(&nd, NDF_NO_VP_RELE); } /* uap->path is always defined. */ - NDINIT(&nd, LOOKUP, MPSAFE | FOLLOW | LOCKLEAF | AUDITVNODE1, + NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | AUDITVNODE1, UIO_USERSPACE, uap->path, td); error = namei(&nd); if (error) goto out; - vfslocked = NDHASGIANT(&nd); mp = nd.ni_vp->v_mount; error = vfs_busy(mp, 0); if (error) { @@ -144,8 +141,6 @@ out: */ if (filename_vp != NULL) vrele(filename_vp); - VFS_UNLOCK_GIANT(fnvfslocked); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -169,7 +164,6 @@ extattr_set_vp(struct vnode *vp, int attrnamespace, const char *attrname, ssize_t cnt; int error; - VFS_ASSERT_GIANT(vp->v_mount); error = vn_start_write(vp, &mp, V_WAIT | PCATCH); if (error) return (error); @@ -221,7 +215,7 @@ extattr_set_fd(td, uap) { struct file *fp; char attrname[EXTATTR_MAXNAMELEN]; - int vfslocked, error; + int error; AUDIT_ARG_FD(uap->fd); AUDIT_ARG_VALUE(uap->attrnamespace); @@ -234,11 +228,9 @@ extattr_set_fd(td, uap) if (error) return (error); - vfslocked = VFS_LOCK_GIANT(fp->f_vnode->v_mount); error = extattr_set_vp(fp->f_vnode, uap->attrnamespace, attrname, uap->data, uap->nbytes, td); fdrop(fp, td); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -256,7 +248,7 @@ extattr_set_file(td, uap) { struct nameidata nd; char attrname[EXTATTR_MAXNAMELEN]; - int vfslocked, error; + int error; AUDIT_ARG_VALUE(uap->attrnamespace); error = copyinstr(uap->attrname, attrname, EXTATTR_MAXNAMELEN, NULL); @@ -264,19 +256,17 @@ extattr_set_file(td, uap) return (error); AUDIT_ARG_TEXT(attrname); - NDINIT(&nd, LOOKUP, MPSAFE | FOLLOW | AUDITVNODE1, UIO_USERSPACE, + NDINIT(&nd, LOOKUP, FOLLOW | AUDITVNODE1, UIO_USERSPACE, uap->path, td); error = namei(&nd); if (error) return (error); NDFREE(&nd, NDF_ONLY_PNBUF); - vfslocked = NDHASGIANT(&nd); error = extattr_set_vp(nd.ni_vp, uap->attrnamespace, attrname, uap->data, uap->nbytes, td); vrele(nd.ni_vp); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -293,7 +283,7 @@ extattr_set_link(td, uap) { struct nameidata nd; char attrname[EXTATTR_MAXNAMELEN]; - int vfslocked, error; + int error; AUDIT_ARG_VALUE(uap->attrnamespace); error = copyinstr(uap->attrname, attrname, EXTATTR_MAXNAMELEN, NULL); @@ -301,19 +291,17 @@ extattr_set_link(td, uap) return (error); AUDIT_ARG_TEXT(attrname); - NDINIT(&nd, LOOKUP, MPSAFE | NOFOLLOW | AUDITVNODE1, UIO_USERSPACE, + NDINIT(&nd, LOOKUP, NOFOLLOW | AUDITVNODE1, UIO_USERSPACE, uap->path, td); error = namei(&nd); if (error) return (error); NDFREE(&nd, NDF_ONLY_PNBUF); - vfslocked = NDHASGIANT(&nd); error = extattr_set_vp(nd.ni_vp, uap->attrnamespace, attrname, uap->data, uap->nbytes, td); vrele(nd.ni_vp); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -337,7 +325,6 @@ extattr_get_vp(struct vnode *vp, int attrnamespace, const char *attrname, size_t size, *sizep; int error; - VFS_ASSERT_GIANT(vp->v_mount); vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); /* @@ -401,7 +388,7 @@ extattr_get_fd(td, uap) { struct file *fp; char attrname[EXTATTR_MAXNAMELEN]; - int vfslocked, error; + int error; AUDIT_ARG_FD(uap->fd); AUDIT_ARG_VALUE(uap->attrnamespace); @@ -414,12 +401,10 @@ extattr_get_fd(td, uap) if (error) return (error); - vfslocked = VFS_LOCK_GIANT(fp->f_vnode->v_mount); error = extattr_get_vp(fp->f_vnode, uap->attrnamespace, attrname, uap->data, uap->nbytes, td); fdrop(fp, td); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -436,7 +421,7 @@ extattr_get_file(td, uap) { struct nameidata nd; char attrname[EXTATTR_MAXNAMELEN]; - int vfslocked, error; + int error; AUDIT_ARG_VALUE(uap->attrnamespace); error = copyinstr(uap->attrname, attrname, EXTATTR_MAXNAMELEN, NULL); @@ -444,19 +429,16 @@ extattr_get_file(td, uap) return (error); AUDIT_ARG_TEXT(attrname); - NDINIT(&nd, LOOKUP, MPSAFE | FOLLOW | AUDITVNODE1, UIO_USERSPACE, - uap->path, td); + NDINIT(&nd, LOOKUP, FOLLOW | AUDITVNODE1, UIO_USERSPACE, uap->path, td); error = namei(&nd); if (error) return (error); NDFREE(&nd, NDF_ONLY_PNBUF); - vfslocked = NDHASGIANT(&nd); error = extattr_get_vp(nd.ni_vp, uap->attrnamespace, attrname, uap->data, uap->nbytes, td); vrele(nd.ni_vp); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -473,7 +455,7 @@ extattr_get_link(td, uap) { struct nameidata nd; char attrname[EXTATTR_MAXNAMELEN]; - int vfslocked, error; + int error; AUDIT_ARG_VALUE(uap->attrnamespace); error = copyinstr(uap->attrname, attrname, EXTATTR_MAXNAMELEN, NULL); @@ -481,19 +463,17 @@ extattr_get_link(td, uap) return (error); AUDIT_ARG_TEXT(attrname); - NDINIT(&nd, LOOKUP, MPSAFE | NOFOLLOW | AUDITVNODE1, UIO_USERSPACE, - uap->path, td); + NDINIT(&nd, LOOKUP, NOFOLLOW | AUDITVNODE1, UIO_USERSPACE, uap->path, + td); error = namei(&nd); if (error) return (error); NDFREE(&nd, NDF_ONLY_PNBUF); - vfslocked = NDHASGIANT(&nd); error = extattr_get_vp(nd.ni_vp, uap->attrnamespace, attrname, uap->data, uap->nbytes, td); vrele(nd.ni_vp); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -514,7 +494,6 @@ extattr_delete_vp(struct vnode *vp, int attrnamespace, const char *attrname, struct mount *mp; int error; - VFS_ASSERT_GIANT(vp->v_mount); error = vn_start_write(vp, &mp, V_WAIT | PCATCH); if (error) return (error); @@ -551,7 +530,7 @@ extattr_delete_fd(td, uap) { struct file *fp; char attrname[EXTATTR_MAXNAMELEN]; - int vfslocked, error; + int error; AUDIT_ARG_FD(uap->fd); AUDIT_ARG_VALUE(uap->attrnamespace); @@ -564,11 +543,9 @@ extattr_delete_fd(td, uap) if (error) return (error); - vfslocked = VFS_LOCK_GIANT(fp->f_vnode->v_mount); error = extattr_delete_vp(fp->f_vnode, uap->attrnamespace, attrname, td); fdrop(fp, td); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -583,7 +560,7 @@ extattr_delete_file(td, uap) { struct nameidata nd; char attrname[EXTATTR_MAXNAMELEN]; - int vfslocked, error; + int error; AUDIT_ARG_VALUE(uap->attrnamespace); error = copyinstr(uap->attrname, attrname, EXTATTR_MAXNAMELEN, NULL); @@ -591,17 +568,14 @@ extattr_delete_file(td, uap) return(error); AUDIT_ARG_TEXT(attrname); - NDINIT(&nd, LOOKUP, MPSAFE | FOLLOW | AUDITVNODE1, UIO_USERSPACE, - uap->path, td); + NDINIT(&nd, LOOKUP, FOLLOW | AUDITVNODE1, UIO_USERSPACE, uap->path, td); error = namei(&nd); if (error) return(error); NDFREE(&nd, NDF_ONLY_PNBUF); - vfslocked = NDHASGIANT(&nd); error = extattr_delete_vp(nd.ni_vp, uap->attrnamespace, attrname, td); vrele(nd.ni_vp); - VFS_UNLOCK_GIANT(vfslocked); return(error); } @@ -616,7 +590,7 @@ extattr_delete_link(td, uap) { struct nameidata nd; char attrname[EXTATTR_MAXNAMELEN]; - int vfslocked, error; + int error; AUDIT_ARG_VALUE(uap->attrnamespace); error = copyinstr(uap->attrname, attrname, EXTATTR_MAXNAMELEN, NULL); @@ -624,17 +598,14 @@ extattr_delete_link(td, uap) return(error); AUDIT_ARG_TEXT(attrname); - NDINIT(&nd, LOOKUP, MPSAFE | NOFOLLOW | AUDITVNODE1, UIO_USERSPACE, - uap->path, td); + NDINIT(&nd, LOOKUP, NOFOLLOW | AUDITVNODE1, UIO_USERSPACE, uap->path, td); error = namei(&nd); if (error) return(error); NDFREE(&nd, NDF_ONLY_PNBUF); - vfslocked = NDHASGIANT(&nd); error = extattr_delete_vp(nd.ni_vp, uap->attrnamespace, attrname, td); vrele(nd.ni_vp); - VFS_UNLOCK_GIANT(vfslocked); return(error); } @@ -658,7 +629,6 @@ extattr_list_vp(struct vnode *vp, int attrnamespace, void *data, ssize_t cnt; int error; - VFS_ASSERT_GIANT(vp->v_mount); vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); auiop = NULL; @@ -715,7 +685,7 @@ extattr_list_fd(td, uap) } */ *uap; { struct file *fp; - int vfslocked, error; + int error; AUDIT_ARG_FD(uap->fd); AUDIT_ARG_VALUE(uap->attrnamespace); @@ -723,12 +693,10 @@ extattr_list_fd(td, uap) if (error) return (error); - vfslocked = VFS_LOCK_GIANT(fp->f_vnode->v_mount); error = extattr_list_vp(fp->f_vnode, uap->attrnamespace, uap->data, uap->nbytes, td); fdrop(fp, td); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -743,22 +711,19 @@ extattr_list_file(td, uap) } */ *uap; { struct nameidata nd; - int vfslocked, error; + int error; AUDIT_ARG_VALUE(uap->attrnamespace); - NDINIT(&nd, LOOKUP, MPSAFE | FOLLOW | AUDITVNODE1, UIO_USERSPACE, - uap->path, td); + NDINIT(&nd, LOOKUP, FOLLOW | AUDITVNODE1, UIO_USERSPACE, uap->path, td); error = namei(&nd); if (error) return (error); NDFREE(&nd, NDF_ONLY_PNBUF); - vfslocked = NDHASGIANT(&nd); error = extattr_list_vp(nd.ni_vp, uap->attrnamespace, uap->data, uap->nbytes, td); vrele(nd.ni_vp); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -773,21 +738,19 @@ extattr_list_link(td, uap) } */ *uap; { struct nameidata nd; - int vfslocked, error; + int error; AUDIT_ARG_VALUE(uap->attrnamespace); - NDINIT(&nd, LOOKUP, MPSAFE | NOFOLLOW | AUDITVNODE1, UIO_USERSPACE, - uap->path, td); + NDINIT(&nd, LOOKUP, NOFOLLOW | AUDITVNODE1, UIO_USERSPACE, uap->path, + td); error = namei(&nd); if (error) return (error); NDFREE(&nd, NDF_ONLY_PNBUF); - vfslocked = NDHASGIANT(&nd); error = extattr_list_vp(nd.ni_vp, uap->attrnamespace, uap->data, uap->nbytes, td); vrele(nd.ni_vp); - VFS_UNLOCK_GIANT(vfslocked); return (error); } diff --git a/sys/kern/vfs_lookup.c b/sys/kern/vfs_lookup.c index 6f10b49..e6c7cb9 100644 --- a/sys/kern/vfs_lookup.c +++ b/sys/kern/vfs_lookup.c @@ -132,10 +132,7 @@ namei(struct nameidata *ndp) struct componentname *cnp = &ndp->ni_cnd; struct thread *td = cnp->cn_thread; struct proc *p = td->td_proc; - int vfslocked; - KASSERT((cnp->cn_flags & MPSAFE) != 0 || mtx_owned(&Giant) != 0, - ("NOT MPSAFE and Giant not held")); ndp->ni_cnd.cn_cred = ndp->ni_cnd.cn_thread->td_ucred; KASSERT(cnp->cn_cred && p, ("namei: bad cred/proc")); KASSERT((cnp->cn_nameiop & (~OPMASK)) == 0, @@ -218,9 +215,7 @@ namei(struct nameidata *ndp) if (error != 0 || dp != NULL) { FILEDESC_SUNLOCK(fdp); if (error == 0 && dp->v_type != VDIR) { - vfslocked = VFS_LOCK_GIANT(dp->v_mount); vrele(dp); - VFS_UNLOCK_GIANT(vfslocked); error = ENOTDIR; } } @@ -237,15 +232,11 @@ namei(struct nameidata *ndp) dp = fdp->fd_cdir; VREF(dp); FILEDESC_SUNLOCK(fdp); - if (ndp->ni_startdir != NULL) { - vfslocked = VFS_LOCK_GIANT(ndp->ni_startdir->v_mount); + if (ndp->ni_startdir != NULL) vrele(ndp->ni_startdir); - VFS_UNLOCK_GIANT(vfslocked); - } } SDT_PROBE(vfs, namei, lookup, entry, dp, cnp->cn_pnbuf, cnp->cn_flags, 0, 0); - vfslocked = VFS_LOCK_GIANT(dp->v_mount); for (;;) { /* * Check if root directory should replace current directory. @@ -254,17 +245,13 @@ namei(struct nameidata *ndp) cnp->cn_nameptr = cnp->cn_pnbuf; if (*(cnp->cn_nameptr) == '/') { vrele(dp); - VFS_UNLOCK_GIANT(vfslocked); while (*(cnp->cn_nameptr) == '/') { cnp->cn_nameptr++; ndp->ni_pathlen--; } dp = ndp->ni_rootdir; - vfslocked = VFS_LOCK_GIANT(dp->v_mount); VREF(dp); } - if (vfslocked) - ndp->ni_cnd.cn_flags |= GIANTHELD; ndp->ni_startdir = dp; error = lookup(ndp); if (error) { @@ -277,8 +264,6 @@ namei(struct nameidata *ndp) 0, 0); return (error); } - vfslocked = (ndp->ni_cnd.cn_flags & GIANTHELD) != 0; - ndp->ni_cnd.cn_flags &= ~GIANTHELD; /* * If not a symbolic link, we're done. */ @@ -292,10 +277,6 @@ namei(struct nameidata *ndp) } else cnp->cn_flags |= HASBUF; - if ((cnp->cn_flags & MPSAFE) == 0) { - VFS_UNLOCK_GIANT(vfslocked); - } else if (vfslocked) - ndp->ni_cnd.cn_flags |= GIANTHELD; SDT_PROBE(vfs, namei, lookup, return, 0, ndp->ni_vp, 0, 0, 0); return (0); @@ -362,7 +343,6 @@ namei(struct nameidata *ndp) vput(ndp->ni_vp); ndp->ni_vp = NULL; vrele(ndp->ni_dvp); - VFS_UNLOCK_GIANT(vfslocked); SDT_PROBE(vfs, namei, lookup, return, error, NULL, 0, 0, 0); return (error); } @@ -466,17 +446,11 @@ lookup(struct nameidata *ndp) int error = 0; int dpunlocked = 0; /* dp has already been unlocked */ struct componentname *cnp = &ndp->ni_cnd; - int vfslocked; /* VFS Giant state for child */ - int dvfslocked; /* VFS Giant state for parent */ - int tvfslocked; int lkflags_save; /* * Setup: break out flag bits into variables. */ - dvfslocked = (ndp->ni_cnd.cn_flags & GIANTHELD) != 0; - vfslocked = 0; - ndp->ni_cnd.cn_flags &= ~GIANTHELD; wantparent = cnp->cn_flags & (LOCKPARENT | WANTPARENT); KASSERT(cnp->cn_nameiop == LOOKUP || wantparent, ("CREATE, DELETE, RENAME require LOCKPARENT or WANTPARENT.")); @@ -630,7 +604,6 @@ dirloop: (cnp->cn_flags & NOCROSSMOUNT) != 0)) { ndp->ni_dvp = dp; ndp->ni_vp = dp; - vfslocked = VFS_LOCK_GIANT(dp->v_mount); VREF(dp); goto nextname; } @@ -642,11 +615,8 @@ dirloop: } tdp = dp; dp = dp->v_mount->mnt_vnodecovered; - tvfslocked = dvfslocked; - dvfslocked = VFS_LOCK_GIANT(dp->v_mount); VREF(dp); vput(tdp); - VFS_UNLOCK_GIANT(tvfslocked); vn_lock(dp, compute_cn_lkflags(dp->v_mount, cnp->cn_lkflags | LK_RETRY)); @@ -668,7 +638,6 @@ unionlookup: ndp->ni_dvp = dp; ndp->ni_vp = NULL; ASSERT_VOP_LOCKED(dp, "lookup"); - VNASSERT(vfslocked == 0, dp, ("lookup: vfslocked %d", vfslocked)); /* * If we have a shared lock we may need to upgrade the lock for the * last operation. @@ -699,11 +668,8 @@ unionlookup: (dp->v_mount->mnt_flag & MNT_UNION)) { tdp = dp; dp = dp->v_mount->mnt_vnodecovered; - tvfslocked = dvfslocked; - dvfslocked = VFS_LOCK_GIANT(dp->v_mount); VREF(dp); vput(tdp); - VFS_UNLOCK_GIANT(tvfslocked); vn_lock(dp, compute_cn_lkflags(dp->v_mount, cnp->cn_lkflags | LK_RETRY)); @@ -757,7 +723,6 @@ unionlookup: } dp = ndp->ni_vp; - vfslocked = VFS_LOCK_GIANT(dp->v_mount); /* * Check to see if the vnode has been mounted on; @@ -768,14 +733,10 @@ unionlookup: if (vfs_busy(mp, 0)) continue; vput(dp); - VFS_UNLOCK_GIANT(vfslocked); - vfslocked = VFS_LOCK_GIANT(mp); if (dp != ndp->ni_dvp) vput(ndp->ni_dvp); else vrele(ndp->ni_dvp); - VFS_UNLOCK_GIANT(dvfslocked); - dvfslocked = 0; vref(vp_crossmp); ndp->ni_dvp = vp_crossmp; error = VFS_ROOT(mp, compute_cn_lkflags(mp, cnp->cn_lkflags), @@ -834,9 +795,6 @@ nextname: vput(ndp->ni_dvp); else vrele(ndp->ni_dvp); - VFS_UNLOCK_GIANT(dvfslocked); - dvfslocked = vfslocked; /* dp becomes dvp in dirloop */ - vfslocked = 0; goto dirloop; } /* @@ -864,8 +822,6 @@ nextname: vput(ndp->ni_dvp); else vrele(ndp->ni_dvp); - VFS_UNLOCK_GIANT(dvfslocked); - dvfslocked = 0; } else if ((cnp->cn_flags & LOCKPARENT) == 0 && ndp->ni_dvp != dp) VOP_UNLOCK(ndp->ni_dvp, 0); @@ -889,10 +845,6 @@ success: goto bad2; } } - if (vfslocked && dvfslocked) - VFS_UNLOCK_GIANT(dvfslocked); /* Only need one */ - if (vfslocked || dvfslocked) - ndp->ni_cnd.cn_flags |= GIANTHELD; return (0); bad2: @@ -903,9 +855,6 @@ bad2: bad: if (!dpunlocked) vput(dp); - VFS_UNLOCK_GIANT(vfslocked); - VFS_UNLOCK_GIANT(dvfslocked); - ndp->ni_cnd.cn_flags &= ~GIANTHELD; ndp->ni_vp = NULL; return (error); } @@ -1170,13 +1119,13 @@ kern_alternate_path(struct thread *td, const char *prefix, const char *path, for (cp = &ptr[len] - 1; *cp != '/'; cp--); *cp = '\0'; - NDINIT(&nd, LOOKUP, FOLLOW | MPSAFE, UIO_SYSSPACE, buf, td); + NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, buf, td); error = namei(&nd); *cp = '/'; if (error != 0) goto keeporig; } else { - NDINIT(&nd, LOOKUP, FOLLOW | MPSAFE, UIO_SYSSPACE, buf, td); + NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, buf, td); error = namei(&nd); if (error != 0) @@ -1190,7 +1139,7 @@ kern_alternate_path(struct thread *td, const char *prefix, const char *path, * root directory and never finding it, because "/" resolves * to the emulation root directory. This is expensive :-( */ - NDINIT(&ndroot, LOOKUP, FOLLOW | MPSAFE, UIO_SYSSPACE, prefix, + NDINIT(&ndroot, LOOKUP, FOLLOW, UIO_SYSSPACE, prefix, td); /* We shouldn't ever get an error from this namei(). */ @@ -1201,13 +1150,11 @@ kern_alternate_path(struct thread *td, const char *prefix, const char *path, NDFREE(&ndroot, NDF_ONLY_PNBUF); vrele(ndroot.ni_vp); - VFS_UNLOCK_GIANT(NDHASGIANT(&ndroot)); } } NDFREE(&nd, NDF_ONLY_PNBUF); vrele(nd.ni_vp); - VFS_UNLOCK_GIANT(NDHASGIANT(&nd)); keeporig: /* If there was an error, use the original path name. */ diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c index daaa5b1..0a0f919 100644 --- a/sys/kern/vfs_subr.c +++ b/sys/kern/vfs_subr.c @@ -89,9 +89,6 @@ __FBSDID("$FreeBSD$"); #include #endif -#define WI_MPSAFEQ 0 -#define WI_GIANTQ 1 - static MALLOC_DEFINE(M_NETADDR, "subr_export_host", "Export host address structure"); static void delmntque(struct vnode *vp); @@ -219,7 +216,7 @@ int prtactive; static int syncer_delayno; static long syncer_mask; LIST_HEAD(synclist, bufobj); -static struct synclist *syncer_workitem_pending[2]; +static struct synclist *syncer_workitem_pending; /* * The sync_mtx protects: * bo->bo_synclist @@ -316,9 +313,7 @@ vntblinit(void *dummy __unused) /* * Initialize the filesystem syncer. */ - syncer_workitem_pending[WI_MPSAFEQ] = hashinit(syncer_maxdelay, M_VNODE, - &syncer_mask); - syncer_workitem_pending[WI_GIANTQ] = hashinit(syncer_maxdelay, M_VNODE, + syncer_workitem_pending = hashinit(syncer_maxdelay, M_VNODE, &syncer_mask); syncer_maxdelay = syncer_mask + 1; mtx_init(&sync_mtx, "Syncer mtx", NULL, MTX_DEF); @@ -713,7 +708,6 @@ static void vnlru_free(int count) { struct vnode *vp; - int vfslocked; mtx_assert(&vnode_free_list_mtx, MA_OWNED); for (; count > 0; count--) { @@ -741,9 +735,7 @@ vnlru_free(int count) vholdl(vp); mtx_unlock(&vnode_free_list_mtx); VI_UNLOCK(vp); - vfslocked = VFS_LOCK_GIANT(vp->v_mount); vtryrecycle(vp); - VFS_UNLOCK_GIANT(vfslocked); /* * If the recycled succeeded this vdrop will actually free * the vnode. If not it will simply place it back on @@ -765,7 +757,7 @@ static void vnlru_proc(void) { struct mount *mp, *nmp; - int done, vfslocked; + int done; struct proc *p = vnlruproc; EVENTHANDLER_REGISTER(shutdown_pre_sync, kproc_shutdown, p, @@ -791,9 +783,7 @@ vnlru_proc(void) nmp = TAILQ_NEXT(mp, mnt_list); continue; } - vfslocked = VFS_LOCK_GIANT(mp); done += vlrureclaim(mp); - VFS_UNLOCK_GIANT(vfslocked); mtx_lock(&mountlist_mtx); nmp = TAILQ_NEXT(mp, mnt_list); vfs_unbusy(mp); @@ -1067,11 +1057,8 @@ insmntque1(struct vnode *vp, struct mount *mp, KASSERT(vp->v_mount == NULL, ("insmntque: vnode already on per mount vnode list")); VNASSERT(mp != NULL, vp, ("Don't call insmntque(foo, NULL)")); -#ifdef DEBUG_VFS_LOCKS - if (!VFS_NEEDSGIANT(mp)) - ASSERT_VOP_ELOCKED(vp, - "insmntque: mp-safe fs and non-locked vp"); -#endif + ASSERT_VOP_ELOCKED(vp, + "insmntque: mp-safe fs and non-locked vp"); MNT_ILOCK(mp); if ((mp->mnt_kern_flag & MNTK_NOINSMNTQ) != 0 && ((mp->mnt_kern_flag & MNTK_UNMOUNTF) != 0 || @@ -1573,8 +1560,6 @@ bgetvp(struct vnode *vp, struct buf *bp) ("bgetvp: bp already attached! %p", bp)); vhold(vp); - if (VFS_NEEDSGIANT(vp->v_mount) || bo->bo_flag & BO_NEEDSGIANT) - bp->b_flags |= B_NEEDSGIANT; bp->b_vp = vp; bp->b_bufobj = bo; /* @@ -1625,7 +1610,7 @@ brelvp(struct buf *bp) static void vn_syncer_add_to_worklist(struct bufobj *bo, int delay) { - int queue, slot; + int slot; ASSERT_BO_LOCKED(bo); @@ -1641,10 +1626,7 @@ vn_syncer_add_to_worklist(struct bufobj *bo, int delay) delay = syncer_maxdelay - 2; slot = (syncer_delayno + delay) & syncer_mask; - queue = VFS_NEEDSGIANT(bo->__bo_vnode->v_mount) ? WI_GIANTQ : - WI_MPSAFEQ; - LIST_INSERT_HEAD(&syncer_workitem_pending[queue][slot], bo, - bo_synclist); + LIST_INSERT_HEAD(&syncer_workitem_pending[slot], bo, bo_synclist); mtx_unlock(&sync_mtx); } @@ -1724,8 +1706,7 @@ sync_vnode(struct synclist *slp, struct bufobj **bo, struct thread *td) static void sched_sync(void) { - struct synclist *gnext, *next; - struct synclist *gslp, *slp; + struct synclist *next, *slp; struct bufobj *bo; long starttime; struct thread *td = curthread; @@ -1771,13 +1752,11 @@ sched_sync(void) * Skip over empty worklist slots when shutting down. */ do { - slp = &syncer_workitem_pending[WI_MPSAFEQ][syncer_delayno]; - gslp = &syncer_workitem_pending[WI_GIANTQ][syncer_delayno]; + slp = &syncer_workitem_pending[syncer_delayno]; syncer_delayno += 1; if (syncer_delayno == syncer_maxdelay) syncer_delayno = 0; - next = &syncer_workitem_pending[WI_MPSAFEQ][syncer_delayno]; - gnext = &syncer_workitem_pending[WI_GIANTQ][syncer_delayno]; + next = &syncer_workitem_pending[syncer_delayno]; /* * If the worklist has wrapped since the * it was emptied of all but syncer vnodes, @@ -1791,7 +1770,7 @@ sched_sync(void) syncer_final_iter = SYNCER_SHUTDOWN_SPEEDUP; } } while (syncer_state != SYNCER_RUNNING && LIST_EMPTY(slp) && - LIST_EMPTY(gslp) && syncer_worklist_len > 0); + syncer_worklist_len > 0); /* * Keep track of the last time there was anything @@ -1811,21 +1790,6 @@ sched_sync(void) continue; } } - if (!LIST_EMPTY(gslp)) { - mtx_unlock(&sync_mtx); - mtx_lock(&Giant); - mtx_lock(&sync_mtx); - while (!LIST_EMPTY(gslp)) { - error = sync_vnode(gslp, &bo, td); - if (error == 1) { - LIST_REMOVE(bo, bo_synclist); - LIST_INSERT_HEAD(gnext, bo, - bo_synclist); - continue; - } - } - mtx_unlock(&Giant); - } if (syncer_state == SYNCER_FINAL_DELAY && syncer_final_iter > 0) syncer_final_iter--; /* @@ -2080,7 +2044,6 @@ vget(struct vnode *vp, int flags, struct thread *td) int error; error = 0; - VFS_ASSERT_GIANT(vp->v_mount); VNASSERT((flags & LK_TYPE_MASK) != 0, vp, ("vget: invalid lock operation")); CTR3(KTR_VFS, "%s: vp %p with flags %d", __func__, vp, flags); @@ -2165,7 +2128,6 @@ vputx(struct vnode *vp, int func) ASSERT_VOP_LOCKED(vp, "vput"); else KASSERT(func == VPUTX_VRELE, ("vputx: wrong func")); - VFS_ASSERT_GIANT(vp->v_mount); CTR2(KTR_VFS, "%s: vp %p", __func__, vp); VI_LOCK(vp); @@ -4293,7 +4255,6 @@ vfs_mark_atime(struct vnode *vp, struct ucred *cred) struct mount *mp; mp = vp->v_mount; - VFS_ASSERT_GIANT(mp); ASSERT_VOP_LOCKED(vp, "vfs_mark_atime"); if (mp != NULL && (mp->mnt_flag & (MNT_NOATIME | MNT_RDONLY)) == 0) (void)VOP_MARKATIME(vp); diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c index aa072ff..3d2b25f 100644 --- a/sys/kern/vfs_syscalls.c +++ b/sys/kern/vfs_syscalls.c @@ -129,7 +129,6 @@ sync(td, uap) struct sync_args *uap; { struct mount *mp, *nmp; - int vfslocked; mtx_lock(&mountlist_mtx); for (mp = TAILQ_FIRST(&mountlist); mp != NULL; mp = nmp) { @@ -137,7 +136,6 @@ sync(td, uap) nmp = TAILQ_NEXT(mp, mnt_list); continue; } - vfslocked = VFS_LOCK_GIANT(mp); if ((mp->mnt_flag & MNT_RDONLY) == 0 && vn_start_write(NULL, &mp, V_NOWAIT) == 0) { MNT_ILOCK(mp); @@ -154,7 +152,6 @@ sync(td, uap) MNT_IUNLOCK(mp); vn_finished_write(mp); } - VFS_UNLOCK_GIANT(vfslocked); mtx_lock(&mountlist_mtx); nmp = TAILQ_NEXT(mp, mnt_list); vfs_unbusy(mp); @@ -185,7 +182,6 @@ quotactl(td, uap) } */ *uap; { struct mount *mp; - int vfslocked; int error; struct nameidata nd; @@ -193,24 +189,20 @@ quotactl(td, uap) AUDIT_ARG_UID(uap->uid); if (!prison_allow(td->td_ucred, PR_ALLOW_QUOTAS)) return (EPERM); - NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | MPSAFE | AUDITVNODE1, + NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | AUDITVNODE1, UIO_USERSPACE, uap->path, td); if ((error = namei(&nd)) != 0) return (error); - vfslocked = NDHASGIANT(&nd); NDFREE(&nd, NDF_ONLY_PNBUF); mp = nd.ni_vp->v_mount; vfs_ref(mp); vput(nd.ni_vp); error = vfs_busy(mp, 0); vfs_rel(mp); - if (error) { - VFS_UNLOCK_GIANT(vfslocked); + if (error) return (error); - } error = VFS_QUOTACTL(mp, uap->cmd, uap->uid, uap->arg); vfs_unbusy(mp); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -287,26 +279,22 @@ kern_statfs(struct thread *td, char *path, enum uio_seg pathseg, { struct mount *mp; struct statfs *sp, sb; - int vfslocked; int error; struct nameidata nd; - NDINIT(&nd, LOOKUP, FOLLOW | LOCKSHARED | LOCKLEAF | MPSAFE | + NDINIT(&nd, LOOKUP, FOLLOW | LOCKSHARED | LOCKLEAF | AUDITVNODE1, pathseg, path, td); error = namei(&nd); if (error) return (error); - vfslocked = NDHASGIANT(&nd); mp = nd.ni_vp->v_mount; vfs_ref(mp); NDFREE(&nd, NDF_ONLY_PNBUF); vput(nd.ni_vp); error = vfs_busy(mp, 0); vfs_rel(mp); - if (error) { - VFS_UNLOCK_GIANT(vfslocked); + if (error) return (error); - } #ifdef MAC error = mac_mount_check_stat(td->td_ucred, mp); if (error) @@ -331,7 +319,6 @@ kern_statfs(struct thread *td, char *path, enum uio_seg pathseg, *buf = *sp; out: vfs_unbusy(mp); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -367,7 +354,6 @@ kern_fstatfs(struct thread *td, int fd, struct statfs *buf) struct file *fp; struct mount *mp; struct statfs *sp, sb; - int vfslocked; struct vnode *vp; int error; @@ -376,7 +362,6 @@ kern_fstatfs(struct thread *td, int fd, struct statfs *buf) if (error) return (error); vp = fp->f_vnode; - vfslocked = VFS_LOCK_GIANT(vp->v_mount); vn_lock(vp, LK_SHARED | LK_RETRY); #ifdef AUDIT AUDIT_ARG_VNODE1(vp); @@ -392,10 +377,8 @@ kern_fstatfs(struct thread *td, int fd, struct statfs *buf) } error = vfs_busy(mp, 0); vfs_rel(mp); - if (error) { - VFS_UNLOCK_GIANT(vfslocked); + if (error) return (error); - } #ifdef MAC error = mac_mount_check_stat(td->td_ucred, mp); if (error) @@ -421,7 +404,6 @@ kern_fstatfs(struct thread *td, int fd, struct statfs *buf) out: if (mp) vfs_unbusy(mp); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -461,7 +443,6 @@ kern_getfsstat(struct thread *td, struct statfs **buf, size_t bufsize, struct mount *mp, *nmp; struct statfs *sfsp, *sp, sb; size_t count, maxcount; - int vfslocked; int error; maxcount = bufsize / sizeof(struct statfs); @@ -498,7 +479,6 @@ kern_getfsstat(struct thread *td, struct statfs **buf, size_t bufsize, nmp = TAILQ_NEXT(mp, mnt_list); continue; } - vfslocked = VFS_LOCK_GIANT(mp); if (sfsp && count < maxcount) { sp = &mp->mnt_stat; /* @@ -516,7 +496,6 @@ kern_getfsstat(struct thread *td, struct statfs **buf, size_t bufsize, if (((flags & (MNT_LAZY|MNT_NOWAIT)) == 0 || (flags & MNT_WAIT)) && (error = VFS_STATFS(mp, sp))) { - VFS_UNLOCK_GIANT(vfslocked); mtx_lock(&mountlist_mtx); nmp = TAILQ_NEXT(mp, mnt_list); vfs_unbusy(mp); @@ -534,13 +513,11 @@ kern_getfsstat(struct thread *td, struct statfs **buf, size_t bufsize, error = copyout(sp, sfsp, sizeof(*sp)); if (error) { vfs_unbusy(mp); - VFS_UNLOCK_GIANT(vfslocked); return (error); } } sfsp++; } - VFS_UNLOCK_GIANT(vfslocked); count++; mtx_lock(&mountlist_mtx); nmp = TAILQ_NEXT(mp, mnt_list); @@ -741,7 +718,6 @@ fchdir(td, uap) struct vnode *vp, *tdp, *vpold; struct mount *mp; struct file *fp; - int vfslocked; int error; AUDIT_ARG_FD(uap->fd); @@ -750,40 +726,29 @@ fchdir(td, uap) vp = fp->f_vnode; VREF(vp); fdrop(fp, td); - vfslocked = VFS_LOCK_GIANT(vp->v_mount); vn_lock(vp, LK_SHARED | LK_RETRY); AUDIT_ARG_VNODE1(vp); error = change_dir(vp, td); while (!error && (mp = vp->v_mountedhere) != NULL) { - int tvfslocked; if (vfs_busy(mp, 0)) continue; - tvfslocked = VFS_LOCK_GIANT(mp); error = VFS_ROOT(mp, LK_SHARED, &tdp); vfs_unbusy(mp); - if (error) { - VFS_UNLOCK_GIANT(tvfslocked); + if (error) break; - } vput(vp); - VFS_UNLOCK_GIANT(vfslocked); vp = tdp; - vfslocked = tvfslocked; } if (error) { vput(vp); - VFS_UNLOCK_GIANT(vfslocked); return (error); } VOP_UNLOCK(vp, 0); - VFS_UNLOCK_GIANT(vfslocked); FILEDESC_XLOCK(fdp); vpold = fdp->fd_cdir; fdp->fd_cdir = vp; FILEDESC_XUNLOCK(fdp); - vfslocked = VFS_LOCK_GIANT(vpold->v_mount); vrele(vpold); - VFS_UNLOCK_GIANT(vfslocked); return (0); } @@ -813,29 +778,23 @@ kern_chdir(struct thread *td, char *path, enum uio_seg pathseg) int error; struct nameidata nd; struct vnode *vp; - int vfslocked; - NDINIT(&nd, LOOKUP, FOLLOW | LOCKSHARED | LOCKLEAF | AUDITVNODE1 | - MPSAFE, pathseg, path, td); + NDINIT(&nd, LOOKUP, FOLLOW | LOCKSHARED | LOCKLEAF | AUDITVNODE1, + pathseg, path, td); if ((error = namei(&nd)) != 0) return (error); - vfslocked = NDHASGIANT(&nd); if ((error = change_dir(nd.ni_vp, td)) != 0) { vput(nd.ni_vp); - VFS_UNLOCK_GIANT(vfslocked); NDFREE(&nd, NDF_ONLY_PNBUF); return (error); } VOP_UNLOCK(nd.ni_vp, 0); - VFS_UNLOCK_GIANT(vfslocked); NDFREE(&nd, NDF_ONLY_PNBUF); FILEDESC_XLOCK(fdp); vp = fdp->fd_cdir; fdp->fd_cdir = nd.ni_vp; FILEDESC_XUNLOCK(fdp); - vfslocked = VFS_LOCK_GIANT(vp->v_mount); vrele(vp); - VFS_UNLOCK_GIANT(vfslocked); return (0); } @@ -896,17 +855,15 @@ chroot(td, uap) { int error; struct nameidata nd; - int vfslocked; error = priv_check(td, PRIV_VFS_CHROOT); if (error) return (error); - NDINIT(&nd, LOOKUP, FOLLOW | LOCKSHARED | LOCKLEAF | MPSAFE | + NDINIT(&nd, LOOKUP, FOLLOW | LOCKSHARED | LOCKLEAF | AUDITVNODE1, UIO_USERSPACE, uap->path, td); error = namei(&nd); if (error) goto error; - vfslocked = NDHASGIANT(&nd); if ((error = change_dir(nd.ni_vp, td)) != 0) goto e_vunlock; #ifdef MAC @@ -916,12 +873,10 @@ chroot(td, uap) VOP_UNLOCK(nd.ni_vp, 0); error = change_root(nd.ni_vp, td); vrele(nd.ni_vp); - VFS_UNLOCK_GIANT(vfslocked); NDFREE(&nd, NDF_ONLY_PNBUF); return (error); e_vunlock: vput(nd.ni_vp); - VFS_UNLOCK_GIANT(vfslocked); error: NDFREE(&nd, NDF_ONLY_PNBUF); return (error); @@ -962,10 +917,8 @@ change_root(vp, td) { struct filedesc *fdp; struct vnode *oldvp; - int vfslocked; int error; - VFS_ASSERT_GIANT(vp->v_mount); fdp = td->td_proc->p_fd; FILEDESC_XLOCK(fdp); if (chroot_allow_open_directories == 0 || @@ -984,9 +937,7 @@ change_root(vp, td) VREF(fdp->fd_jdir); } FILEDESC_XUNLOCK(fdp); - vfslocked = VFS_LOCK_GIANT(oldvp->v_mount); vrele(oldvp); - VFS_UNLOCK_GIANT(vfslocked); return (0); } @@ -1053,7 +1004,6 @@ kern_openat(struct thread *td, int fd, char *path, enum uio_seg pathseg, int type, indx, error; struct flock lf; struct nameidata nd; - int vfslocked; AUDIT_ARG_FFLAGS(flags); AUDIT_ARG_MODE(mode); @@ -1078,7 +1028,7 @@ kern_openat(struct thread *td, int fd, char *path, enum uio_seg pathseg, /* Set the flags early so the finit in devfs can pick them up. */ fp->f_flag = flags & FMASK; cmode = ((mode &~ fdp->fd_cmask) & ALLPERMS) &~ S_ISTXT; - NDINIT_AT(&nd, LOOKUP, FOLLOW | AUDITVNODE1 | MPSAFE, pathseg, path, fd, + NDINIT_AT(&nd, LOOKUP, FOLLOW | AUDITVNODE1, pathseg, path, fd, td); td->td_dupfd = -1; /* XXX check for fdopen */ error = vn_open(&nd, &flags, cmode, fp); @@ -1119,7 +1069,6 @@ kern_openat(struct thread *td, int fd, char *path, enum uio_seg pathseg, return (error); } td->td_dupfd = 0; - vfslocked = NDHASGIANT(&nd); NDFREE(&nd, NDF_ONLY_PNBUF); vp = nd.ni_vp; @@ -1167,7 +1116,6 @@ kern_openat(struct thread *td, int fd, char *path, enum uio_seg pathseg, if (error) goto bad; } - VFS_UNLOCK_GIANT(vfslocked); /* * Release our private reference, leaving the one associated with * the descriptor table intact. @@ -1176,7 +1124,6 @@ kern_openat(struct thread *td, int fd, char *path, enum uio_seg pathseg, td->td_retval[0] = indx; return (0); bad: - VFS_UNLOCK_GIANT(vfslocked); fdclose(fdp, fp, indx, td); fdrop(fp, td); return (error); @@ -1263,7 +1210,6 @@ kern_mknodat(struct thread *td, int fd, char *path, enum uio_seg pathseg, int error; int whiteout = 0; struct nameidata nd; - int vfslocked; AUDIT_ARG_MODE(mode); AUDIT_ARG_DEV(dev); @@ -1290,11 +1236,10 @@ kern_mknodat(struct thread *td, int fd, char *path, enum uio_seg pathseg, return (error); restart: bwillwrite(); - NDINIT_AT(&nd, CREATE, LOCKPARENT | SAVENAME | MPSAFE | AUDITVNODE1, + NDINIT_AT(&nd, CREATE, LOCKPARENT | SAVENAME | AUDITVNODE1, pathseg, path, fd, td); if ((error = namei(&nd)) != 0) return (error); - vfslocked = NDHASGIANT(&nd); vp = nd.ni_vp; if (vp != NULL) { NDFREE(&nd, NDF_ONLY_PNBUF); @@ -1303,7 +1248,6 @@ restart: else vput(nd.ni_dvp); vrele(vp); - VFS_UNLOCK_GIANT(vfslocked); return (EEXIST); } else { VATTR_NULL(&vattr); @@ -1332,7 +1276,6 @@ restart: if (vn_start_write(nd.ni_dvp, &mp, V_NOWAIT) != 0) { NDFREE(&nd, NDF_ONLY_PNBUF); vput(nd.ni_dvp); - VFS_UNLOCK_GIANT(vfslocked); if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0) return (error); goto restart; @@ -1355,7 +1298,6 @@ restart: NDFREE(&nd, NDF_ONLY_PNBUF); vput(nd.ni_dvp); vn_finished_write(mp); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -1410,16 +1352,14 @@ kern_mkfifoat(struct thread *td, int fd, char *path, enum uio_seg pathseg, struct vattr vattr; int error; struct nameidata nd; - int vfslocked; AUDIT_ARG_MODE(mode); restart: bwillwrite(); - NDINIT_AT(&nd, CREATE, LOCKPARENT | SAVENAME | MPSAFE | AUDITVNODE1, + NDINIT_AT(&nd, CREATE, LOCKPARENT | SAVENAME | AUDITVNODE1, pathseg, path, fd, td); if ((error = namei(&nd)) != 0) return (error); - vfslocked = NDHASGIANT(&nd); if (nd.ni_vp != NULL) { NDFREE(&nd, NDF_ONLY_PNBUF); if (nd.ni_vp == nd.ni_dvp) @@ -1427,13 +1367,11 @@ restart: else vput(nd.ni_dvp); vrele(nd.ni_vp); - VFS_UNLOCK_GIANT(vfslocked); return (EEXIST); } if (vn_start_write(nd.ni_dvp, &mp, V_NOWAIT) != 0) { NDFREE(&nd, NDF_ONLY_PNBUF); vput(nd.ni_dvp); - VFS_UNLOCK_GIANT(vfslocked); if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0) return (error); goto restart; @@ -1455,7 +1393,6 @@ out: #endif vput(nd.ni_dvp); vn_finished_write(mp); - VFS_UNLOCK_GIANT(vfslocked); NDFREE(&nd, NDF_ONLY_PNBUF); return (error); } @@ -1556,33 +1493,27 @@ kern_linkat(struct thread *td, int fd1, int fd2, char *path1, char *path2, struct vnode *vp; struct mount *mp; struct nameidata nd; - int vfslocked; - int lvfslocked; int error; bwillwrite(); - NDINIT_AT(&nd, LOOKUP, follow | MPSAFE | AUDITVNODE1, segflg, path1, + NDINIT_AT(&nd, LOOKUP, follow | AUDITVNODE1, segflg, path1, fd1, td); if ((error = namei(&nd)) != 0) return (error); - vfslocked = NDHASGIANT(&nd); NDFREE(&nd, NDF_ONLY_PNBUF); vp = nd.ni_vp; if (vp->v_type == VDIR) { vrele(vp); - VFS_UNLOCK_GIANT(vfslocked); return (EPERM); /* POSIX */ } if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0) { vrele(vp); - VFS_UNLOCK_GIANT(vfslocked); return (error); } - NDINIT_AT(&nd, CREATE, LOCKPARENT | SAVENAME | MPSAFE | AUDITVNODE2, + NDINIT_AT(&nd, CREATE, LOCKPARENT | SAVENAME | AUDITVNODE2, segflg, path2, fd2, td); if ((error = namei(&nd)) == 0) { - lvfslocked = NDHASGIANT(&nd); if (nd.ni_vp != NULL) { if (nd.ni_dvp == nd.ni_vp) vrele(nd.ni_dvp); @@ -1604,11 +1535,9 @@ kern_linkat(struct thread *td, int fd1, int fd2, char *path1, char *path2, vput(nd.ni_dvp); } NDFREE(&nd, NDF_ONLY_PNBUF); - VFS_UNLOCK_GIANT(lvfslocked); } vrele(vp); vn_finished_write(mp); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -1664,7 +1593,6 @@ kern_symlinkat(struct thread *td, char *path1, int fd, char *path2, char *syspath; int error; struct nameidata nd; - int vfslocked; if (segflg == UIO_SYSSPACE) { syspath = path1; @@ -1676,11 +1604,10 @@ kern_symlinkat(struct thread *td, char *path1, int fd, char *path2, AUDIT_ARG_TEXT(syspath); restart: bwillwrite(); - NDINIT_AT(&nd, CREATE, LOCKPARENT | SAVENAME | MPSAFE | AUDITVNODE1, + NDINIT_AT(&nd, CREATE, LOCKPARENT | SAVENAME | AUDITVNODE1, segflg, path2, fd, td); if ((error = namei(&nd)) != 0) goto out; - vfslocked = NDHASGIANT(&nd); if (nd.ni_vp) { NDFREE(&nd, NDF_ONLY_PNBUF); if (nd.ni_vp == nd.ni_dvp) @@ -1688,14 +1615,12 @@ restart: else vput(nd.ni_dvp); vrele(nd.ni_vp); - VFS_UNLOCK_GIANT(vfslocked); error = EEXIST; goto out; } if (vn_start_write(nd.ni_dvp, &mp, V_NOWAIT) != 0) { NDFREE(&nd, NDF_ONLY_PNBUF); vput(nd.ni_dvp); - VFS_UNLOCK_GIANT(vfslocked); if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0) goto out; goto restart; @@ -1718,7 +1643,6 @@ out2: NDFREE(&nd, NDF_ONLY_PNBUF); vput(nd.ni_dvp); vn_finished_write(mp); - VFS_UNLOCK_GIANT(vfslocked); out: if (segflg != UIO_SYSSPACE) uma_zfree(namei_zone, syspath); @@ -1738,16 +1662,14 @@ undelete(td, uap) int error; struct mount *mp; struct nameidata nd; - int vfslocked; restart: bwillwrite(); - NDINIT(&nd, DELETE, LOCKPARENT | DOWHITEOUT | MPSAFE | AUDITVNODE1, + NDINIT(&nd, DELETE, LOCKPARENT | DOWHITEOUT | AUDITVNODE1, UIO_USERSPACE, uap->path, td); error = namei(&nd); if (error) return (error); - vfslocked = NDHASGIANT(&nd); if (nd.ni_vp != NULLVP || !(nd.ni_cnd.cn_flags & ISWHITEOUT)) { NDFREE(&nd, NDF_ONLY_PNBUF); @@ -1757,13 +1679,11 @@ restart: vput(nd.ni_dvp); if (nd.ni_vp) vrele(nd.ni_vp); - VFS_UNLOCK_GIANT(vfslocked); return (EEXIST); } if (vn_start_write(nd.ni_dvp, &mp, V_NOWAIT) != 0) { NDFREE(&nd, NDF_ONLY_PNBUF); vput(nd.ni_dvp); - VFS_UNLOCK_GIANT(vfslocked); if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0) return (error); goto restart; @@ -1772,7 +1692,6 @@ restart: NDFREE(&nd, NDF_ONLY_PNBUF); vput(nd.ni_dvp); vn_finished_write(mp); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -1834,15 +1753,13 @@ kern_unlinkat(struct thread *td, int fd, char *path, enum uio_seg pathseg, int error; struct nameidata nd; struct stat sb; - int vfslocked; restart: bwillwrite(); - NDINIT_AT(&nd, DELETE, LOCKPARENT | LOCKLEAF | MPSAFE | AUDITVNODE1, + NDINIT_AT(&nd, DELETE, LOCKPARENT | LOCKLEAF | AUDITVNODE1, pathseg, path, fd, td); if ((error = namei(&nd)) != 0) return (error == EINVAL ? EPERM : error); - vfslocked = NDHASGIANT(&nd); vp = nd.ni_vp; if (vp->v_type == VDIR && oldinum == 0) { error = EPERM; /* POSIX */ @@ -1867,7 +1784,6 @@ restart: vrele(vp); else vput(vp); - VFS_UNLOCK_GIANT(vfslocked); if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0) return (error); @@ -1891,7 +1807,6 @@ out: vrele(vp); else vput(vp); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -1922,7 +1837,6 @@ lseek(td, uap) struct vattr vattr; off_t offset; int error, noneg; - int vfslocked; AUDIT_ARG_FD(uap->fd); if ((error = fget(td, uap->fd, &fp)) != 0) @@ -1932,7 +1846,6 @@ lseek(td, uap) return (ESPIPE); } vp = fp->f_vnode; - vfslocked = VFS_LOCK_GIANT(vp->v_mount); noneg = (vp->v_type != VCHR); offset = uap->offset; switch (uap->whence) { @@ -1978,7 +1891,6 @@ lseek(td, uap) *(off_t *)(td->td_retval) = fp->f_offset; drop: fdrop(fp, td); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -2117,7 +2029,6 @@ kern_accessat(struct thread *td, int fd, char *path, enum uio_seg pathseg, struct ucred *cred, *tmpcred; struct vnode *vp; struct nameidata nd; - int vfslocked; int error; /* @@ -2134,17 +2045,15 @@ kern_accessat(struct thread *td, int fd, char *path, enum uio_seg pathseg, } else cred = tmpcred = td->td_ucred; AUDIT_ARG_VALUE(mode); - NDINIT_AT(&nd, LOOKUP, FOLLOW | LOCKSHARED | LOCKLEAF | MPSAFE | + NDINIT_AT(&nd, LOOKUP, FOLLOW | LOCKSHARED | LOCKLEAF | AUDITVNODE1, pathseg, path, fd, td); if ((error = namei(&nd)) != 0) goto out1; - vfslocked = NDHASGIANT(&nd); vp = nd.ni_vp; error = vn_access(vp, mode, tmpcred, td); NDFREE(&nd, NDF_ONLY_PNBUF); vput(vp); - VFS_UNLOCK_GIANT(vfslocked); out1: if (!(flags & AT_EACCESS)) { td->td_ucred = cred; @@ -2339,18 +2248,17 @@ kern_statat_vnhook(struct thread *td, int flag, int fd, char *path, { struct nameidata nd; struct stat sb; - int error, vfslocked; + int error; if (flag & ~AT_SYMLINK_NOFOLLOW) return (EINVAL); NDINIT_AT(&nd, LOOKUP, ((flag & AT_SYMLINK_NOFOLLOW) ? NOFOLLOW : - FOLLOW) | LOCKSHARED | LOCKLEAF | AUDITVNODE1 | MPSAFE, pathseg, + FOLLOW) | LOCKSHARED | LOCKLEAF | AUDITVNODE1, pathseg, path, fd, td); if ((error = namei(&nd)) != 0) return (error); - vfslocked = NDHASGIANT(&nd); error = vn_stat(nd.ni_vp, &sb, td->td_ucred, NOCRED, td); if (!error) { SDT_PROBE(vfs, , stat, mode, path, sb.st_mode, 0, 0, 0); @@ -2361,7 +2269,6 @@ kern_statat_vnhook(struct thread *td, int flag, int fd, char *path, } NDFREE(&nd, NDF_ONLY_PNBUF); vput(nd.ni_vp); - VFS_UNLOCK_GIANT(vfslocked); if (error) return (error); *sbp = sb; @@ -2532,13 +2439,12 @@ kern_pathconf(struct thread *td, char *path, enum uio_seg pathseg, int name, u_long flags) { struct nameidata nd; - int error, vfslocked; + int error; - NDINIT(&nd, LOOKUP, LOCKSHARED | LOCKLEAF | MPSAFE | AUDITVNODE1 | - flags, pathseg, path, td); + NDINIT(&nd, LOOKUP, LOCKSHARED | LOCKLEAF | AUDITVNODE1 | flags, + pathseg, path, td); if ((error = namei(&nd)) != 0) return (error); - vfslocked = NDHASGIANT(&nd); NDFREE(&nd, NDF_ONLY_PNBUF); /* If asynchronous I/O is available, it works for all files. */ @@ -2547,7 +2453,6 @@ kern_pathconf(struct thread *td, char *path, enum uio_seg pathseg, int name, else error = VOP_PATHCONF(nd.ni_vp, name, td->td_retval); vput(nd.ni_vp); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -2608,24 +2513,21 @@ kern_readlinkat(struct thread *td, int fd, char *path, enum uio_seg pathseg, struct uio auio; int error; struct nameidata nd; - int vfslocked; if (count > INT_MAX) return (EINVAL); - NDINIT_AT(&nd, LOOKUP, NOFOLLOW | LOCKSHARED | LOCKLEAF | MPSAFE | + NDINIT_AT(&nd, LOOKUP, NOFOLLOW | LOCKSHARED | LOCKLEAF | AUDITVNODE1, pathseg, path, fd, td); if ((error = namei(&nd)) != 0) return (error); NDFREE(&nd, NDF_ONLY_PNBUF); - vfslocked = NDHASGIANT(&nd); vp = nd.ni_vp; #ifdef MAC error = mac_vnode_check_readlink(td->td_ucred, vp); if (error) { vput(vp); - VFS_UNLOCK_GIANT(vfslocked); return (error); } #endif @@ -2644,7 +2546,6 @@ kern_readlinkat(struct thread *td, int fd, char *path, enum uio_seg pathseg, error = VOP_READLINK(vp, &auio, td->td_ucred); } vput(vp); - VFS_UNLOCK_GIANT(vfslocked); td->td_retval[0] = count - auio.uio_resid; return (error); } @@ -2708,18 +2609,15 @@ chflags(td, uap) { int error; struct nameidata nd; - int vfslocked; AUDIT_ARG_FFLAGS(uap->flags); - NDINIT(&nd, LOOKUP, FOLLOW | MPSAFE | AUDITVNODE1, UIO_USERSPACE, + NDINIT(&nd, LOOKUP, FOLLOW | AUDITVNODE1, UIO_USERSPACE, uap->path, td); if ((error = namei(&nd)) != 0) return (error); NDFREE(&nd, NDF_ONLY_PNBUF); - vfslocked = NDHASGIANT(&nd); error = setfflags(td, nd.ni_vp, uap->flags); vrele(nd.ni_vp); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -2736,18 +2634,15 @@ lchflags(td, uap) { int error; struct nameidata nd; - int vfslocked; AUDIT_ARG_FFLAGS(uap->flags); - NDINIT(&nd, LOOKUP, NOFOLLOW | MPSAFE | AUDITVNODE1, UIO_USERSPACE, + NDINIT(&nd, LOOKUP, NOFOLLOW | AUDITVNODE1, UIO_USERSPACE, uap->path, td); if ((error = namei(&nd)) != 0) return (error); - vfslocked = NDHASGIANT(&nd); NDFREE(&nd, NDF_ONLY_PNBUF); error = setfflags(td, nd.ni_vp, uap->flags); vrele(nd.ni_vp); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -2769,21 +2664,18 @@ fchflags(td, uap) } */ *uap; { struct file *fp; - int vfslocked; int error; AUDIT_ARG_FD(uap->fd); AUDIT_ARG_FFLAGS(uap->flags); if ((error = getvnode(td->td_proc->p_fd, uap->fd, &fp)) != 0) return (error); - vfslocked = VFS_LOCK_GIANT(fp->f_vnode->v_mount); #ifdef AUDIT vn_lock(fp->f_vnode, LK_SHARED | LK_RETRY); AUDIT_ARG_VNODE1(fp->f_vnode); VOP_UNLOCK(fp->f_vnode, 0); #endif error = setfflags(td, fp->f_vnode, uap->flags); - VFS_UNLOCK_GIANT(vfslocked); fdrop(fp, td); return (error); } @@ -2895,20 +2787,17 @@ kern_fchmodat(struct thread *td, int fd, char *path, enum uio_seg pathseg, { int error; struct nameidata nd; - int vfslocked; int follow; AUDIT_ARG_MODE(mode); follow = (flag & AT_SYMLINK_NOFOLLOW) ? NOFOLLOW : FOLLOW; - NDINIT_AT(&nd, LOOKUP, follow | MPSAFE | AUDITVNODE1, pathseg, path, + NDINIT_AT(&nd, LOOKUP, follow | AUDITVNODE1, pathseg, path, fd, td); if ((error = namei(&nd)) != 0) return (error); - vfslocked = NDHASGIANT(&nd); NDFREE(&nd, NDF_ONLY_PNBUF); error = setfmode(td, nd.ni_vp, mode); vrele(nd.ni_vp); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -2930,21 +2819,18 @@ fchmod(td, uap) } */ *uap; { struct file *fp; - int vfslocked; int error; AUDIT_ARG_FD(uap->fd); AUDIT_ARG_MODE(uap->mode); if ((error = getvnode(td->td_proc->p_fd, uap->fd, &fp)) != 0) return (error); - vfslocked = VFS_LOCK_GIANT(fp->f_vnode->v_mount); #ifdef AUDIT vn_lock(fp->f_vnode, LK_SHARED | LK_RETRY); AUDIT_ARG_VNODE1(fp->f_vnode); VOP_UNLOCK(fp->f_vnode, 0); #endif error = setfmode(td, fp->f_vnode, uap->mode); - VFS_UNLOCK_GIANT(vfslocked); fdrop(fp, td); return (error); } @@ -3038,20 +2924,18 @@ kern_fchownat(struct thread *td, int fd, char *path, enum uio_seg pathseg, int uid, int gid, int flag) { struct nameidata nd; - int error, vfslocked, follow; + int error, follow; AUDIT_ARG_OWNER(uid, gid); follow = (flag & AT_SYMLINK_NOFOLLOW) ? NOFOLLOW : FOLLOW; - NDINIT_AT(&nd, LOOKUP, follow | MPSAFE | AUDITVNODE1, pathseg, path, + NDINIT_AT(&nd, LOOKUP, follow | AUDITVNODE1, pathseg, path, fd, td); if ((error = namei(&nd)) != 0) return (error); - vfslocked = NDHASGIANT(&nd); NDFREE(&nd, NDF_ONLY_PNBUF); error = setfown(td, nd.ni_vp, uid, gid); vrele(nd.ni_vp); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -3107,21 +2991,18 @@ fchown(td, uap) } */ *uap; { struct file *fp; - int vfslocked; int error; AUDIT_ARG_FD(uap->fd); AUDIT_ARG_OWNER(uap->uid, uap->gid); if ((error = getvnode(td->td_proc->p_fd, uap->fd, &fp)) != 0) return (error); - vfslocked = VFS_LOCK_GIANT(fp->f_vnode->v_mount); #ifdef AUDIT vn_lock(fp->f_vnode, LK_SHARED | LK_RETRY); AUDIT_ARG_VNODE1(fp->f_vnode); VOP_UNLOCK(fp->f_vnode, 0); #endif error = setfown(td, fp->f_vnode, uap->uid, uap->gid); - VFS_UNLOCK_GIANT(vfslocked); fdrop(fp, td); return (error); } @@ -3253,20 +3134,17 @@ kern_utimesat(struct thread *td, int fd, char *path, enum uio_seg pathseg, { struct nameidata nd; struct timespec ts[2]; - int error, vfslocked; + int error; if ((error = getutimes(tptr, tptrseg, ts)) != 0) return (error); - NDINIT_AT(&nd, LOOKUP, FOLLOW | MPSAFE | AUDITVNODE1, pathseg, path, - fd, td); + NDINIT_AT(&nd, LOOKUP, FOLLOW | AUDITVNODE1, pathseg, path, fd, td); if ((error = namei(&nd)) != 0) return (error); - vfslocked = NDHASGIANT(&nd); NDFREE(&nd, NDF_ONLY_PNBUF); error = setutimes(td, nd.ni_vp, ts, 2, tptr == NULL); vrele(nd.ni_vp); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -3299,18 +3177,15 @@ kern_lutimes(struct thread *td, char *path, enum uio_seg pathseg, struct timespec ts[2]; int error; struct nameidata nd; - int vfslocked; if ((error = getutimes(tptr, tptrseg, ts)) != 0) return (error); - NDINIT(&nd, LOOKUP, NOFOLLOW | MPSAFE | AUDITVNODE1, pathseg, path, td); + NDINIT(&nd, LOOKUP, NOFOLLOW | AUDITVNODE1, pathseg, path, td); if ((error = namei(&nd)) != 0) return (error); - vfslocked = NDHASGIANT(&nd); NDFREE(&nd, NDF_ONLY_PNBUF); error = setutimes(td, nd.ni_vp, ts, 2, tptr == NULL); vrele(nd.ni_vp); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -3341,7 +3216,6 @@ kern_futimes(struct thread *td, int fd, struct timeval *tptr, { struct timespec ts[2]; struct file *fp; - int vfslocked; int error; AUDIT_ARG_FD(fd); @@ -3349,14 +3223,12 @@ kern_futimes(struct thread *td, int fd, struct timeval *tptr, return (error); if ((error = getvnode(td->td_proc->p_fd, fd, &fp)) != 0) return (error); - vfslocked = VFS_LOCK_GIANT(fp->f_vnode->v_mount); #ifdef AUDIT vn_lock(fp->f_vnode, LK_SHARED | LK_RETRY); AUDIT_ARG_VNODE1(fp->f_vnode); VOP_UNLOCK(fp->f_vnode, 0); #endif error = setutimes(td, fp->f_vnode, ts, 2, tptr == NULL); - VFS_UNLOCK_GIANT(vfslocked); fdrop(fp, td); return (error); } @@ -3392,18 +3264,15 @@ kern_truncate(struct thread *td, char *path, enum uio_seg pathseg, off_t length) struct vattr vattr; int error; struct nameidata nd; - int vfslocked; if (length < 0) return(EINVAL); - NDINIT(&nd, LOOKUP, FOLLOW | MPSAFE | AUDITVNODE1, pathseg, path, td); + NDINIT(&nd, LOOKUP, FOLLOW | AUDITVNODE1, pathseg, path, td); if ((error = namei(&nd)) != 0) return (error); - vfslocked = NDHASGIANT(&nd); vp = nd.ni_vp; if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0) { vrele(vp); - VFS_UNLOCK_GIANT(vfslocked); return (error); } NDFREE(&nd, NDF_ONLY_PNBUF); @@ -3422,7 +3291,6 @@ kern_truncate(struct thread *td, char *path, enum uio_seg pathseg, off_t length) } vput(vp); vn_finished_write(mp); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -3495,14 +3363,12 @@ fsync(td, uap) struct vnode *vp; struct mount *mp; struct file *fp; - int vfslocked; int error, lock_flags; AUDIT_ARG_FD(uap->fd); if ((error = getvnode(td->td_proc->p_fd, uap->fd, &fp)) != 0) return (error); vp = fp->f_vnode; - vfslocked = VFS_LOCK_GIANT(vp->v_mount); if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0) goto drop; if (MNT_SHARED_WRITES(mp) || @@ -3523,7 +3389,6 @@ fsync(td, uap) VOP_UNLOCK(vp, 0); vn_finished_write(mp); drop: - VFS_UNLOCK_GIANT(vfslocked); fdrop(fp, td); return (error); } @@ -3580,23 +3445,19 @@ kern_renameat(struct thread *td, int oldfd, char *old, int newfd, char *new, struct mount *mp = NULL; struct vnode *tvp, *fvp, *tdvp; struct nameidata fromnd, tond; - int tvfslocked; - int fvfslocked; int error; bwillwrite(); #ifdef MAC - NDINIT_AT(&fromnd, DELETE, LOCKPARENT | LOCKLEAF | SAVESTART | MPSAFE | + NDINIT_AT(&fromnd, DELETE, LOCKPARENT | LOCKLEAF | SAVESTART | AUDITVNODE1, pathseg, old, oldfd, td); #else - NDINIT_AT(&fromnd, DELETE, WANTPARENT | SAVESTART | MPSAFE | + NDINIT_AT(&fromnd, DELETE, WANTPARENT | SAVESTART | AUDITVNODE1, pathseg, old, oldfd, td); #endif if ((error = namei(&fromnd)) != 0) return (error); - fvfslocked = NDHASGIANT(&fromnd); - tvfslocked = 0; #ifdef MAC error = mac_vnode_check_rename_from(td->td_ucred, fromnd.ni_dvp, fromnd.ni_vp, &fromnd.ni_cnd); @@ -3614,7 +3475,7 @@ kern_renameat(struct thread *td, int oldfd, char *old, int newfd, char *new, goto out1; } NDINIT_AT(&tond, RENAME, LOCKPARENT | LOCKLEAF | NOCACHE | SAVESTART | - MPSAFE | AUDITVNODE2, pathseg, new, newfd, td); + AUDITVNODE2, pathseg, new, newfd, td); if (fromnd.ni_vp->v_type == VDIR) tond.ni_cnd.cn_flags |= WILLBEDIR; if ((error = namei(&tond)) != 0) { @@ -3627,7 +3488,6 @@ kern_renameat(struct thread *td, int oldfd, char *old, int newfd, char *new, vn_finished_write(mp); goto out1; } - tvfslocked = NDHASGIANT(&tond); tdvp = tond.ni_dvp; tvp = tond.ni_vp; if (tvp != NULL) { @@ -3677,8 +3537,6 @@ out: out1: if (fromnd.ni_startdir) vrele(fromnd.ni_startdir); - VFS_UNLOCK_GIANT(fvfslocked); - VFS_UNLOCK_GIANT(tvfslocked); if (error == -1) return (0); return (error); @@ -3735,17 +3593,15 @@ kern_mkdirat(struct thread *td, int fd, char *path, enum uio_seg segflg, struct vattr vattr; int error; struct nameidata nd; - int vfslocked; AUDIT_ARG_MODE(mode); restart: bwillwrite(); - NDINIT_AT(&nd, CREATE, LOCKPARENT | SAVENAME | MPSAFE | AUDITVNODE1, + NDINIT_AT(&nd, CREATE, LOCKPARENT | SAVENAME | AUDITVNODE1, segflg, path, fd, td); nd.ni_cnd.cn_flags |= WILLBEDIR; if ((error = namei(&nd)) != 0) return (error); - vfslocked = NDHASGIANT(&nd); vp = nd.ni_vp; if (vp != NULL) { NDFREE(&nd, NDF_ONLY_PNBUF); @@ -3759,13 +3615,11 @@ restart: else vput(nd.ni_dvp); vrele(vp); - VFS_UNLOCK_GIANT(vfslocked); return (EEXIST); } if (vn_start_write(nd.ni_dvp, &mp, V_NOWAIT) != 0) { NDFREE(&nd, NDF_ONLY_PNBUF); vput(nd.ni_dvp); - VFS_UNLOCK_GIANT(vfslocked); if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0) return (error); goto restart; @@ -3788,7 +3642,6 @@ out: if (!error) vput(nd.ni_vp); vn_finished_write(mp); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -3825,15 +3678,13 @@ kern_rmdirat(struct thread *td, int fd, char *path, enum uio_seg pathseg) struct vnode *vp; int error; struct nameidata nd; - int vfslocked; restart: bwillwrite(); - NDINIT_AT(&nd, DELETE, LOCKPARENT | LOCKLEAF | MPSAFE | AUDITVNODE1, + NDINIT_AT(&nd, DELETE, LOCKPARENT | LOCKLEAF | AUDITVNODE1, pathseg, path, fd, td); if ((error = namei(&nd)) != 0) return (error); - vfslocked = NDHASGIANT(&nd); vp = nd.ni_vp; if (vp->v_type != VDIR) { error = ENOTDIR; @@ -3866,7 +3717,6 @@ restart: vrele(nd.ni_dvp); else vput(nd.ni_dvp); - VFS_UNLOCK_GIANT(vfslocked); if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0) return (error); goto restart; @@ -3880,7 +3730,6 @@ out: vrele(nd.ni_dvp); else vput(nd.ni_dvp); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -3912,7 +3761,7 @@ ogetdirentries(td, uap) struct iovec aiov, kiov; struct dirent *dp, *edp; caddr_t dirbuf; - int error, eofflag, readcnt, vfslocked; + int error, eofflag, readcnt; long loff; /* XXX arbitrary sanity limit on `count'. */ @@ -3926,9 +3775,7 @@ ogetdirentries(td, uap) } vp = fp->f_vnode; unionread: - vfslocked = VFS_LOCK_GIANT(vp->v_mount); if (vp->v_type != VDIR) { - VFS_UNLOCK_GIANT(vfslocked); fdrop(fp, td); return (EINVAL); } @@ -3946,7 +3793,6 @@ unionread: error = mac_vnode_check_readdir(td->td_ucred, vp); if (error) { VOP_UNLOCK(vp, 0); - VFS_UNLOCK_GIANT(vfslocked); fdrop(fp, td); return (error); } @@ -4004,7 +3850,6 @@ unionread: } if (error) { VOP_UNLOCK(vp, 0); - VFS_UNLOCK_GIANT(vfslocked); fdrop(fp, td); return (error); } @@ -4018,11 +3863,9 @@ unionread: fp->f_data = vp; fp->f_offset = 0; vput(tvp); - VFS_UNLOCK_GIANT(vfslocked); goto unionread; } VOP_UNLOCK(vp, 0); - VFS_UNLOCK_GIANT(vfslocked); error = copyout(&loff, uap->basep, sizeof(long)); fdrop(fp, td); td->td_retval[0] = uap->count - auio.uio_resid; @@ -4070,7 +3913,6 @@ kern_getdirentries(struct thread *td, int fd, char *buf, u_int count, struct file *fp; struct uio auio; struct iovec aiov; - int vfslocked; long loff; int error, eofflag; @@ -4085,9 +3927,7 @@ kern_getdirentries(struct thread *td, int fd, char *buf, u_int count, } vp = fp->f_vnode; unionread: - vfslocked = VFS_LOCK_GIANT(vp->v_mount); if (vp->v_type != VDIR) { - VFS_UNLOCK_GIANT(vfslocked); error = EINVAL; goto fail; } @@ -4111,7 +3951,6 @@ unionread: fp->f_offset = auio.uio_offset; if (error) { VOP_UNLOCK(vp, 0); - VFS_UNLOCK_GIANT(vfslocked); goto fail; } if (count == auio.uio_resid && @@ -4124,11 +3963,9 @@ unionread: fp->f_data = vp; fp->f_offset = 0; vput(tvp); - VFS_UNLOCK_GIANT(vfslocked); goto unionread; } VOP_UNLOCK(vp, 0); - VFS_UNLOCK_GIANT(vfslocked); *basep = loff; td->td_retval[0] = count - auio.uio_resid; fail: @@ -4205,13 +4042,11 @@ revoke(td, uap) struct vattr vattr; int error; struct nameidata nd; - int vfslocked; - NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | MPSAFE | AUDITVNODE1, + NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | AUDITVNODE1, UIO_USERSPACE, uap->path, td); if ((error = namei(&nd)) != 0) return (error); - vfslocked = NDHASGIANT(&nd); vp = nd.ni_vp; NDFREE(&nd, NDF_ONLY_PNBUF); if (vp->v_type != VCHR) { @@ -4235,7 +4070,6 @@ revoke(td, uap) VOP_REVOKE(vp, REVOKEALL); out: vput(vp); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -4281,25 +4115,22 @@ lgetfh(td, uap) struct nameidata nd; fhandle_t fh; register struct vnode *vp; - int vfslocked; int error; error = priv_check(td, PRIV_VFS_GETFH); if (error) return (error); - NDINIT(&nd, LOOKUP, NOFOLLOW | LOCKLEAF | MPSAFE | AUDITVNODE1, + NDINIT(&nd, LOOKUP, NOFOLLOW | LOCKLEAF | AUDITVNODE1, UIO_USERSPACE, uap->fname, td); error = namei(&nd); if (error) return (error); - vfslocked = NDHASGIANT(&nd); NDFREE(&nd, NDF_ONLY_PNBUF); vp = nd.ni_vp; bzero(&fh, sizeof(fh)); fh.fh_fsid = vp->v_mount->mnt_stat.f_fsid; error = VOP_VPTOFH(vp, &fh.fh_fid); vput(vp); - VFS_UNLOCK_GIANT(vfslocked); if (error) return (error); error = copyout(&fh, uap->fhp, sizeof (fh)); @@ -4320,25 +4151,22 @@ getfh(td, uap) struct nameidata nd; fhandle_t fh; register struct vnode *vp; - int vfslocked; int error; error = priv_check(td, PRIV_VFS_GETFH); if (error) return (error); - NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | MPSAFE | AUDITVNODE1, + NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | AUDITVNODE1, UIO_USERSPACE, uap->fname, td); error = namei(&nd); if (error) return (error); - vfslocked = NDHASGIANT(&nd); NDFREE(&nd, NDF_ONLY_PNBUF); vp = nd.ni_vp; bzero(&fh, sizeof(fh)); fh.fh_fsid = vp->v_mount->mnt_stat.f_fsid; error = VOP_VPTOFH(vp, &fh.fh_fid); vput(vp); - VFS_UNLOCK_GIANT(vfslocked); if (error) return (error); error = copyout(&fh, uap->fhp, sizeof (fh)); @@ -4378,7 +4206,6 @@ fhopen(td, uap) int fmode, error, type; accmode_t accmode; struct file *nfp; - int vfslocked; int indx; error = priv_check(td, PRIV_VFS_FHOPEN); @@ -4395,7 +4222,6 @@ fhopen(td, uap) mp = vfs_busyfs(&fhp.fh_fsid); if (mp == NULL) return (ESTALE); - vfslocked = VFS_LOCK_GIANT(mp); /* now give me my vnode, it gets returned to me locked */ error = VFS_FHTOVP(mp, &fhp.fh_fid, &vp); vfs_unbusy(mp); @@ -4525,14 +4351,12 @@ fhopen(td, uap) VOP_UNLOCK(vp, 0); fdrop(fp, td); - VFS_UNLOCK_GIANT(vfslocked); td->td_retval[0] = indx; return (0); bad: vput(vp); out: - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -4557,7 +4381,6 @@ fhstat(td, uap) fhandle_t fh; struct mount *mp; struct vnode *vp; - int vfslocked; int error; error = priv_check(td, PRIV_VFS_FHSTAT); @@ -4568,16 +4391,12 @@ fhstat(td, uap) return (error); if ((mp = vfs_busyfs(&fh.fh_fsid)) == NULL) return (ESTALE); - vfslocked = VFS_LOCK_GIANT(mp); error = VFS_FHTOVP(mp, &fh.fh_fid, &vp); vfs_unbusy(mp); - if (error) { - VFS_UNLOCK_GIANT(vfslocked); + if (error) return (error); - } error = vn_stat(vp, &sb, td->td_ucred, NOCRED, td); vput(vp); - VFS_UNLOCK_GIANT(vfslocked); if (error) return (error); error = copyout(&sb, uap->sb, sizeof(sb)); @@ -4620,7 +4439,6 @@ kern_fhstatfs(struct thread *td, fhandle_t fh, struct statfs *buf) struct statfs *sp; struct mount *mp; struct vnode *vp; - int vfslocked; int error; error = priv_check(td, PRIV_VFS_FHSTATFS); @@ -4628,11 +4446,9 @@ kern_fhstatfs(struct thread *td, fhandle_t fh, struct statfs *buf) return (error); if ((mp = vfs_busyfs(&fh.fh_fsid)) == NULL) return (ESTALE); - vfslocked = VFS_LOCK_GIANT(mp); error = VFS_FHTOVP(mp, &fh.fh_fid, &vp); if (error) { vfs_unbusy(mp); - VFS_UNLOCK_GIANT(vfslocked); return (error); } vput(vp); @@ -4656,6 +4472,5 @@ kern_fhstatfs(struct thread *td, fhandle_t fh, struct statfs *buf) *buf = *sp; out: vfs_unbusy(mp); - VFS_UNLOCK_GIANT(vfslocked); return (error); } diff --git a/sys/kern/vfs_vnops.c b/sys/kern/vfs_vnops.c index d0b713c..fe11735 100644 --- a/sys/kern/vfs_vnops.c +++ b/sys/kern/vfs_vnops.c @@ -112,16 +112,12 @@ vn_open_cred(struct nameidata *ndp, int *flagp, int cmode, u_int vn_open_flags, struct vattr *vap = &vat; int fmode, error; accmode_t accmode; - int vfslocked, mpsafe; - mpsafe = ndp->ni_cnd.cn_flags & MPSAFE; restart: - vfslocked = 0; fmode = *flagp; if (fmode & O_CREAT) { ndp->ni_cnd.cn_nameiop = CREATE; - ndp->ni_cnd.cn_flags = ISOPEN | LOCKPARENT | LOCKLEAF | - MPSAFE; + ndp->ni_cnd.cn_flags = ISOPEN | LOCKPARENT | LOCKLEAF; if ((fmode & O_EXCL) == 0 && (fmode & O_NOFOLLOW) == 0) ndp->ni_cnd.cn_flags |= FOLLOW; if (!(vn_open_flags & VN_OPEN_NOAUDIT)) @@ -129,9 +125,6 @@ restart: bwillwrite(); if ((error = namei(ndp)) != 0) return (error); - vfslocked = NDHASGIANT(ndp); - if (!mpsafe) - ndp->ni_cnd.cn_flags &= ~MPSAFE; if (ndp->ni_vp == NULL) { VATTR_NULL(vap); vap->va_type = VREG; @@ -141,7 +134,6 @@ restart: if (vn_start_write(ndp->ni_dvp, &mp, V_NOWAIT) != 0) { NDFREE(ndp, NDF_ONLY_PNBUF); vput(ndp->ni_dvp); - VFS_UNLOCK_GIANT(vfslocked); if ((error = vn_start_write(NULL, &mp, V_XSLEEP | PCATCH)) != 0) return (error); @@ -157,7 +149,6 @@ restart: vput(ndp->ni_dvp); vn_finished_write(mp); if (error) { - VFS_UNLOCK_GIANT(vfslocked); NDFREE(ndp, NDF_ONLY_PNBUF); return (error); } @@ -179,17 +170,13 @@ restart: } else { ndp->ni_cnd.cn_nameiop = LOOKUP; ndp->ni_cnd.cn_flags = ISOPEN | - ((fmode & O_NOFOLLOW) ? NOFOLLOW : FOLLOW) | - LOCKLEAF | MPSAFE; + ((fmode & O_NOFOLLOW) ? NOFOLLOW : FOLLOW) | LOCKLEAF; if (!(fmode & FWRITE)) ndp->ni_cnd.cn_flags |= LOCKSHARED; if (!(vn_open_flags & VN_OPEN_NOAUDIT)) ndp->ni_cnd.cn_flags |= AUDITVNODE1; if ((error = namei(ndp)) != 0) return (error); - if (!mpsafe) - ndp->ni_cnd.cn_flags &= ~MPSAFE; - vfslocked = NDHASGIANT(ndp); vp = ndp->ni_vp; } if (vp->v_type == VLNK) { @@ -238,13 +225,10 @@ restart: vp->v_writecount++; *flagp = fmode; ASSERT_VOP_LOCKED(vp, "vn_open_cred"); - if (!mpsafe) - VFS_UNLOCK_GIANT(vfslocked); return (0); bad: NDFREE(ndp, NDF_ONLY_PNBUF); vput(vp); - VFS_UNLOCK_GIANT(vfslocked); *flagp = fmode; ndp->ni_vp = NULL; return (error); @@ -290,8 +274,6 @@ vn_close(vp, flags, file_cred, td) else lock_flags = LK_EXCLUSIVE; - VFS_ASSERT_GIANT(vp->v_mount); - vn_start_write(vp, &mp, V_WAIT); vn_lock(vp, lock_flags | LK_RETRY); if (flags & FWRITE) { @@ -371,8 +353,6 @@ vn_rdwr(rw, vp, base, len, offset, segflg, ioflg, active_cred, file_cred, struct ucred *cred; int error, lock_flags; - VFS_ASSERT_GIANT(vp->v_mount); - if ((ioflg & IO_NODELOCKED) == 0) { mp = NULL; if (rw == UIO_WRITE) { @@ -461,8 +441,6 @@ vn_rdwr_inchunks(rw, vp, base, len, offset, segflg, ioflg, active_cred, int error = 0; int iaresid; - VFS_ASSERT_GIANT(vp->v_mount); - do { int chunk; @@ -507,7 +485,6 @@ vn_read(fp, uio, active_cred, flags, td) struct vnode *vp; int error, ioflag; struct mtx *mtxp; - int vfslocked; KASSERT(uio->uio_td == td, ("uio_td %p is not td %p", uio->uio_td, td)); @@ -518,7 +495,6 @@ vn_read(fp, uio, active_cred, flags, td) ioflag |= IO_NDELAY; if (fp->f_flag & O_DIRECT) ioflag |= IO_DIRECT; - vfslocked = VFS_LOCK_GIANT(vp->v_mount); /* * According to McKusick the vn lock was protecting f_offset here. * It is now protected by the FOFFSET_LOCKED flag. @@ -555,7 +531,6 @@ vn_read(fp, uio, active_cred, flags, td) } fp->f_nextoff = uio->uio_offset; VOP_UNLOCK(vp, 0); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -573,12 +548,10 @@ vn_write(fp, uio, active_cred, flags, td) struct vnode *vp; struct mount *mp; int error, ioflag, lock_flags; - int vfslocked; KASSERT(uio->uio_td == td, ("uio_td %p is not td %p", uio->uio_td, td)); vp = fp->f_vnode; - vfslocked = VFS_LOCK_GIANT(vp->v_mount); if (vp->v_type == VREG) bwillwrite(); ioflag = IO_UNIT; @@ -620,7 +593,6 @@ vn_write(fp, uio, active_cred, flags, td) if (vp->v_type != VCHR) vn_finished_write(mp); unlock: - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -637,16 +609,12 @@ vn_truncate(fp, length, active_cred, td) struct vattr vattr; struct mount *mp; struct vnode *vp; - int vfslocked; int error; vp = fp->f_vnode; - vfslocked = VFS_LOCK_GIANT(vp->v_mount); error = vn_start_write(vp, &mp, V_WAIT | PCATCH); - if (error) { - VFS_UNLOCK_GIANT(vfslocked); + if (error) return (error); - } vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); if (vp->v_type == VDIR) { error = EISDIR; @@ -666,7 +634,6 @@ vn_truncate(fp, length, active_cred, td) out: VOP_UNLOCK(vp, 0); vn_finished_write(mp); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -681,14 +648,11 @@ vn_statfile(fp, sb, active_cred, td) struct thread *td; { struct vnode *vp = fp->f_vnode; - int vfslocked; int error; - vfslocked = VFS_LOCK_GIANT(vp->v_mount); vn_lock(vp, LK_SHARED | LK_RETRY); error = vn_stat(vp, sb, active_cred, fp->f_cred, td); VOP_UNLOCK(vp, 0); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -817,10 +781,8 @@ vn_ioctl(fp, com, data, active_cred, td) { struct vnode *vp = fp->f_vnode; struct vattr vattr; - int vfslocked; int error; - vfslocked = VFS_LOCK_GIANT(vp->v_mount); error = ENOTTY; switch (vp->v_type) { case VREG: @@ -842,7 +804,6 @@ vn_ioctl(fp, com, data, active_cred, td) default: break; } - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -857,11 +818,9 @@ vn_poll(fp, events, active_cred, td) struct thread *td; { struct vnode *vp; - int vfslocked; int error; vp = fp->f_vnode; - vfslocked = VFS_LOCK_GIANT(vp->v_mount); #ifdef MAC vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); error = mac_vnode_check_poll(active_cred, fp->f_cred, vp); @@ -870,7 +829,6 @@ vn_poll(fp, events, active_cred, td) #endif error = VOP_POLL(vp, events, fp->f_cred, td); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -919,12 +877,10 @@ vn_closefile(fp, td) { struct vnode *vp; struct flock lf; - int vfslocked; int error; vp = fp->f_vnode; - vfslocked = VFS_LOCK_GIANT(vp->v_mount); if (fp->f_type == DTYPE_VNODE && fp->f_flag & FHASLOCK) { lf.l_whence = SEEK_SET; lf.l_start = 0; @@ -936,7 +892,6 @@ vn_closefile(fp, td) fp->f_ops = &badfileops; error = vn_close(vp, fp->f_flag, fp->f_cred, td); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -1176,14 +1131,10 @@ vfs_write_resume(mp) static int vn_kqfilter(struct file *fp, struct knote *kn) { - int vfslocked; int error; - vfslocked = VFS_LOCK_GIANT(fp->f_vnode->v_mount); error = VOP_KQFILTER(fp->f_vnode, kn); - VFS_UNLOCK_GIANT(vfslocked); - - return error; + return (error); } /* diff --git a/sys/nfsserver/nfs.h b/sys/nfsserver/nfs.h index bb1893e..1c2435d 100644 --- a/sys/nfsserver/nfs.h +++ b/sys/nfsserver/nfs.h @@ -262,7 +262,7 @@ int nfsrv_commit(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, struct mbuf **mrq); int nfsrv_create(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, struct mbuf **mrq); -int nfsrv_fhtovp(fhandle_t *, int, struct vnode **, int *, +int nfsrv_fhtovp(fhandle_t *, int, struct vnode **, struct nfsrv_descript *, struct nfssvc_sock *, struct sockaddr *, int *, int); int nfsrv_setpublicfs(struct mount *, struct netexport *, diff --git a/sys/nfsserver/nfs_serv.c b/sys/nfsserver/nfs_serv.c index d1be5e5..d0cd6c7 100644 --- a/sys/nfsserver/nfs_serv.c +++ b/sys/nfsserver/nfs_serv.c @@ -158,32 +158,6 @@ ndclear(struct nameidata *nd) } /* - * Takes two vfslocked integers and returns with at most one - * reference to giant. The return value indicates whether giant - * is held by either lock. This simplifies nfsrv ops by allowing - * them to track only one vfslocked var. - */ -static __inline int -nfsrv_lockedpair(int vfs1, int vfs2) -{ - - if (vfs1 && vfs2) - VFS_UNLOCK_GIANT(vfs2); - - return (vfs1 | vfs2); -} - -static __inline int -nfsrv_lockedpair_nd(int vfs1, struct nameidata *nd) -{ - int vfs2; - - vfs2 = NDHASGIANT(nd); - - return nfsrv_lockedpair(vfs1, vfs2); -} - -/* * nfs v3 access service */ int @@ -204,17 +178,14 @@ nfsrv3_access(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, struct vattr vattr, *vap = &vattr; u_long testmode, nfsmode; int v3 = (nfsd->nd_flag & ND_NFSV3); - int vfslocked; nfsdbprintf(("%s %d\n", __FILE__, __LINE__)); if (!v3) panic("nfsrv3_access: v3 proc called on a v2 connection"); - vfslocked = 0; fhp = &nfh.fh_generic; nfsm_srvmtofh(fhp); tl = nfsm_dissect_nonblock(u_int32_t *, NFSX_UNSIGNED); - error = nfsrv_fhtovp(fhp, 1, &vp, &vfslocked, nfsd, slp, - nam, &rdonly, TRUE); + error = nfsrv_fhtovp(fhp, 1, &vp, nfsd, slp, nam, &rdonly, TRUE); if (error) { nfsm_reply(NFSX_UNSIGNED); nfsm_srvpostop_attr(1, NULL); @@ -250,7 +221,6 @@ nfsrv3_access(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, nfsmout: if (vp) vput(vp); - VFS_UNLOCK_GIANT(vfslocked); return(error); } @@ -274,14 +244,11 @@ nfsrv_getattr(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, caddr_t bpos; int error = 0, rdonly; struct mbuf *mb, *mreq; - int vfslocked; nfsdbprintf(("%s %d\n", __FILE__, __LINE__)); - vfslocked = 0; fhp = &nfh.fh_generic; nfsm_srvmtofh(fhp); - error = nfsrv_fhtovp(fhp, 1, &vp, &vfslocked, nfsd, slp, nam, - &rdonly, TRUE); + error = nfsrv_fhtovp(fhp, 1, &vp, nfsd, slp, nam, &rdonly, TRUE); if (error) { nfsm_reply(0); error = 0; @@ -303,7 +270,6 @@ nfsrv_getattr(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, nfsmout: if (vp) vput(vp); - VFS_UNLOCK_GIANT(vfslocked); return(error); } @@ -332,18 +298,14 @@ nfsrv_setattr(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, struct mbuf *mb, *mreq; struct timespec guard = { 0, 0 }; struct mount *mp = NULL; - int tvfslocked; - int vfslocked; nfsdbprintf(("%s %d\n", __FILE__, __LINE__)); - vfslocked = 0; fhp = &nfh.fh_generic; nfsm_srvmtofh(fhp); if ((mp = vfs_getvfs(&fhp->fh_fsid)) == NULL) { error = ESTALE; goto out; } - vfslocked = VFS_LOCK_GIANT(mp); (void) vn_start_write(NULL, &mp, V_WAIT); vfs_rel(mp); /* The write holds a ref. */ VATTR_NULL(vap); @@ -389,9 +351,7 @@ nfsrv_setattr(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, /* * Now that we have all the fields, lets do it. */ - error = nfsrv_fhtovp(fhp, 1, &vp, &tvfslocked, nfsd, slp, - nam, &rdonly, TRUE); - vfslocked = nfsrv_lockedpair(vfslocked, tvfslocked); + error = nfsrv_fhtovp(fhp, 1, &vp, nfsd, slp, nam, &rdonly, TRUE); if (error) { nfsm_reply(2 * NFSX_UNSIGNED); if (v3) @@ -461,7 +421,6 @@ nfsmout: if (vp) vput(vp); vn_finished_write(mp); - VFS_UNLOCK_GIANT(vfslocked); return(error); } @@ -486,12 +445,9 @@ nfsrv_lookup(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, int v3 = (nfsd->nd_flag & ND_NFSV3), pubflag; struct mbuf *mb, *mreq; struct vattr va, dirattr, *vap = &va; - int tvfslocked; - int vfslocked; nfsdbprintf(("%s %d\n", __FILE__, __LINE__)); ndclear(&nd); - vfslocked = 0; fhp = &nfh.fh_generic; nfsm_srvmtofh(fhp); @@ -501,10 +457,9 @@ nfsrv_lookup(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, nd.ni_cnd.cn_cred = cred; nd.ni_cnd.cn_nameiop = LOOKUP; - nd.ni_cnd.cn_flags = LOCKLEAF | SAVESTART | MPSAFE; + nd.ni_cnd.cn_flags = LOCKLEAF | SAVESTART; error = nfs_namei(&nd, nfsd, fhp, len, slp, nam, &md, &dpos, &dirp, v3, &dirattr, &dirattr_ret, pubflag); - vfslocked = NDHASGIANT(&nd); /* * namei failure, only dirp to cleanup. Clear out garbarge from @@ -551,14 +506,8 @@ nfsrv_lookup(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, nfs_pub.np_index; ind.ni_startdir = nd.ni_vp; VREF(ind.ni_startdir); - ind.ni_cnd.cn_flags &= ~GIANTHELD; - tvfslocked = VFS_LOCK_GIANT(ind.ni_startdir->v_mount); - if (tvfslocked) - nd.ni_cnd.cn_flags |= GIANTHELD; error = lookup(&ind); ind.ni_dvp = NULL; - vfslocked = nfsrv_lockedpair_nd(vfslocked, &ind); - ind.ni_cnd.cn_flags &= ~GIANTHELD; if (error == 0) { /* @@ -645,7 +594,6 @@ nfsmout: vrele(ndp->ni_startdir); } NDFREE(&nd, NDF_ONLY_PNBUF); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -673,10 +621,8 @@ nfsrv_readlink(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, nfsfh_t nfh; fhandle_t *fhp; struct uio io, *uiop = &io; - int vfslocked; nfsdbprintf(("%s %d\n", __FILE__, __LINE__)); - vfslocked = 0; #ifndef nolint mp = NULL; #endif @@ -712,8 +658,7 @@ nfsrv_readlink(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, uiop->uio_rw = UIO_READ; uiop->uio_segflg = UIO_SYSSPACE; uiop->uio_td = NULL; - error = nfsrv_fhtovp(fhp, 1, &vp, &vfslocked, nfsd, slp, - nam, &rdonly, TRUE); + error = nfsrv_fhtovp(fhp, 1, &vp, nfsd, slp, nam, &rdonly, TRUE); if (error) { nfsm_reply(2 * NFSX_UNSIGNED); if (v3) @@ -752,7 +697,6 @@ nfsmout: m_freem(mp3); if (vp) vput(vp); - VFS_UNLOCK_GIANT(vfslocked); return(error); } @@ -786,11 +730,8 @@ nfsrv_read(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, struct nfsheur *nh; off_t off; int ioflag = 0; - int vfslocked; - nfsdbprintf(("%s %d\n", __FILE__, __LINE__)); - vfslocked = 0; fhp = &nfh.fh_generic; nfsm_srvmtofh(fhp); if (v3) { @@ -808,8 +749,7 @@ nfsrv_read(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, * as well. */ - error = nfsrv_fhtovp(fhp, 1, &vp, &vfslocked, nfsd, slp, - nam, &rdonly, TRUE); + error = nfsrv_fhtovp(fhp, 1, &vp, nfsd, slp, nam, &rdonly, TRUE); if (error) { vp = NULL; nfsm_reply(2 * NFSX_UNSIGNED); @@ -1002,7 +942,6 @@ nfsrv_read(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, nfsmout: if (vp) vput(vp); - VFS_UNLOCK_GIANT(vfslocked); return(error); } @@ -1037,11 +976,8 @@ nfsrv_write(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, struct uio io, *uiop = &io; off_t off; struct mount *mntp = NULL; - int tvfslocked; - int vfslocked; nfsdbprintf(("%s %d\n", __FILE__, __LINE__)); - vfslocked = 0; if (mrep == NULL) { *mrq = NULL; error = 0; @@ -1053,7 +989,6 @@ nfsrv_write(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, error = ESTALE; goto ereply; } - vfslocked = VFS_LOCK_GIANT(mntp); (void) vn_start_write(NULL, &mntp, V_WAIT); vfs_rel(mntp); /* The write holds a ref. */ if (v3) { @@ -1109,9 +1044,7 @@ nfsrv_write(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, error = 0; goto nfsmout; } - error = nfsrv_fhtovp(fhp, 1, &vp, &tvfslocked, nfsd, slp, - nam, &rdonly, TRUE); - vfslocked = nfsrv_lockedpair(vfslocked, tvfslocked); + error = nfsrv_fhtovp(fhp, 1, &vp, nfsd, slp, nam, &rdonly, TRUE); if (error) { vp = NULL; nfsm_reply(2 * NFSX_UNSIGNED); @@ -1220,7 +1153,6 @@ nfsmout: if (vp) vput(vp); vn_finished_write(mntp); - VFS_UNLOCK_GIANT(vfslocked); return(error); } @@ -1252,11 +1184,8 @@ nfsrv_create(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, u_quad_t tempsize; struct timespec cverf; struct mount *mp = NULL; - int tvfslocked; - int vfslocked; nfsdbprintf(("%s %d\n", __FILE__, __LINE__)); - vfslocked = 0; #ifndef nolint rdev = 0; #endif @@ -1268,14 +1197,13 @@ nfsrv_create(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, error = ESTALE; goto ereply; } - vfslocked = VFS_LOCK_GIANT(mp); (void) vn_start_write(NULL, &mp, V_WAIT); vfs_rel(mp); /* The write holds a ref. */ nfsm_srvnamesiz(len); nd.ni_cnd.cn_cred = cred; nd.ni_cnd.cn_nameiop = CREATE; - nd.ni_cnd.cn_flags = LOCKPARENT | LOCKLEAF | SAVESTART | MPSAFE; + nd.ni_cnd.cn_flags = LOCKPARENT | LOCKLEAF | SAVESTART; /* * Call namei and do initial cleanup to get a few things @@ -1288,7 +1216,6 @@ nfsrv_create(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, */ error = nfs_namei(&nd, nfsd, fhp, len, slp, nam, &md, &dpos, &dirp, v3, &dirfor, &dirfor_ret, FALSE); - vfslocked = nfsrv_lockedpair_nd(vfslocked, &nd); if (dirp && !v3) { vrele(dirp); dirp = NULL; @@ -1424,13 +1351,8 @@ nfsrv_create(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, nd.ni_cnd.cn_flags &= ~(LOCKPARENT); nd.ni_cnd.cn_thread = curthread; nd.ni_cnd.cn_cred = cred; - tvfslocked = VFS_LOCK_GIANT(nd.ni_startdir->v_mount); - if (tvfslocked) - nd.ni_cnd.cn_flags |= GIANTHELD; error = lookup(&nd); nd.ni_dvp = NULL; - vfslocked = nfsrv_lockedpair_nd(vfslocked, &nd); - nd.ni_cnd.cn_flags &= ~GIANTHELD; if (error) goto ereply; @@ -1518,7 +1440,6 @@ nfsmout: vrele(dirp); NDFREE(&nd, NDF_ONLY_PNBUF); vn_finished_write(mp); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -1548,11 +1469,8 @@ nfsrv_mknod(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, fhandle_t *fhp; struct mount *mp = NULL; int v3 = (nfsd->nd_flag & ND_NFSV3); - int tvfslocked; - int vfslocked; nfsdbprintf(("%s %d\n", __FILE__, __LINE__)); - vfslocked = 0; if (!v3) panic("nfsrv_mknod: v3 proc called on a v2 connection"); ndclear(&nd); @@ -1563,14 +1481,13 @@ nfsrv_mknod(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, error = ESTALE; goto ereply; } - vfslocked = VFS_LOCK_GIANT(mp); (void) vn_start_write(NULL, &mp, V_WAIT); vfs_rel(mp); /* The write holds a ref. */ nfsm_srvnamesiz(len); nd.ni_cnd.cn_cred = cred; nd.ni_cnd.cn_nameiop = CREATE; - nd.ni_cnd.cn_flags = LOCKPARENT | LOCKLEAF | SAVESTART | MPSAFE; + nd.ni_cnd.cn_flags = LOCKPARENT | LOCKLEAF | SAVESTART; /* * Handle nfs_namei() call. If an error occurs, the nd structure @@ -1580,7 +1497,6 @@ nfsrv_mknod(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, error = nfs_namei(&nd, nfsd, fhp, len, slp, nam, &md, &dpos, &dirp, v3, &dirfor, &dirfor_ret, FALSE); - vfslocked = nfsrv_lockedpair_nd(vfslocked, &nd); if (error) { nfsm_reply(NFSX_WCCDATA(1)); nfsm_srvwcc_data(dirfor_ret, &dirfor, diraft_ret, &diraft); @@ -1640,13 +1556,8 @@ nfsrv_mknod(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, nd.ni_cnd.cn_flags &= ~(LOCKPARENT); nd.ni_cnd.cn_thread = td; nd.ni_cnd.cn_cred = td->td_ucred; - tvfslocked = VFS_LOCK_GIANT(nd.ni_startdir->v_mount); - if (tvfslocked) - nd.ni_cnd.cn_flags |= GIANTHELD; error = lookup(&nd); nd.ni_dvp = NULL; - vfslocked = nfsrv_lockedpair_nd(vfslocked, &nd); - nd.ni_cnd.cn_flags &= ~GIANTHELD; if (error) goto out; @@ -1698,7 +1609,6 @@ ereply: nfsm_srvwcc_data(dirfor_ret, &dirfor, diraft_ret, &diraft); } vn_finished_write(mp); - VFS_UNLOCK_GIANT(vfslocked); return (0); nfsmout: if (nd.ni_dvp) { @@ -1715,7 +1625,6 @@ nfsmout: vrele(nd.ni_startdir); NDFREE(&nd, NDF_ONLY_PNBUF); vn_finished_write(mp); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -1740,11 +1649,9 @@ nfsrv_remove(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, nfsfh_t nfh; fhandle_t *fhp; struct mount *mp = NULL; - int vfslocked; nfsdbprintf(("%s %d\n", __FILE__, __LINE__)); ndclear(&nd); - vfslocked = 0; fhp = &nfh.fh_generic; nfsm_srvmtofh(fhp); @@ -1752,17 +1659,15 @@ nfsrv_remove(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, error = ESTALE; goto ereply; } - vfslocked = VFS_LOCK_GIANT(mp); (void) vn_start_write(NULL, &mp, V_WAIT); vfs_rel(mp); /* The write holds a ref. */ nfsm_srvnamesiz(len); nd.ni_cnd.cn_cred = cred; nd.ni_cnd.cn_nameiop = DELETE; - nd.ni_cnd.cn_flags = LOCKPARENT | LOCKLEAF | MPSAFE; + nd.ni_cnd.cn_flags = LOCKPARENT | LOCKLEAF; error = nfs_namei(&nd, nfsd, fhp, len, slp, nam, &md, &dpos, &dirp, v3, &dirfor, &dirfor_ret, FALSE); - vfslocked = nfsrv_lockedpair_nd(vfslocked, &nd); if (dirp && !v3) { vrele(dirp); dirp = NULL; @@ -1824,7 +1729,6 @@ nfsmout: if (nd.ni_vp) vput(nd.ni_vp); vn_finished_write(mp); - VFS_UNLOCK_GIANT(vfslocked); return(error); } @@ -1852,10 +1756,8 @@ nfsrv_rename(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, fhandle_t *ffhp, *tfhp; uid_t saved_uid; struct mount *mp = NULL; - int vfslocked; nfsdbprintf(("%s %d\n", __FILE__, __LINE__)); - vfslocked = 0; #ifndef nolint fvp = NULL; #endif @@ -1874,7 +1776,6 @@ nfsrv_rename(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, error = ESTALE; goto out1; } - vfslocked = VFS_LOCK_GIANT(mp); (void) vn_start_write(NULL, &mp, V_WAIT); vfs_rel(mp); /* The write holds a ref. */ nfsm_srvnamesiz(len); @@ -1885,10 +1786,9 @@ nfsrv_rename(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, saved_uid = cred->cr_uid; fromnd.ni_cnd.cn_cred = cred; fromnd.ni_cnd.cn_nameiop = DELETE; - fromnd.ni_cnd.cn_flags = WANTPARENT | SAVESTART | MPSAFE; + fromnd.ni_cnd.cn_flags = WANTPARENT | SAVESTART; error = nfs_namei(&fromnd, nfsd, ffhp, len, slp, nam, &md, &dpos, &fdirp, v3, &fdirfor, &fdirfor_ret, FALSE); - vfslocked = nfsrv_lockedpair_nd(vfslocked, &fromnd); if (fdirp && !v3) { vrele(fdirp); fdirp = NULL; @@ -1908,10 +1808,9 @@ nfsrv_rename(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, cred->cr_uid = saved_uid; tond.ni_cnd.cn_cred = cred; tond.ni_cnd.cn_nameiop = RENAME; - tond.ni_cnd.cn_flags = LOCKPARENT | LOCKLEAF | NOCACHE | SAVESTART | MPSAFE; + tond.ni_cnd.cn_flags = LOCKPARENT | LOCKLEAF | NOCACHE | SAVESTART; error = nfs_namei(&tond, nfsd, tfhp, len2, slp, nam, &md, &dpos, &tdirp, v3, &tdirfor, &tdirfor_ret, FALSE); - vfslocked = nfsrv_lockedpair_nd(vfslocked, &tond); if (tdirp && !v3) { vrele(tdirp); tdirp = NULL; @@ -2057,7 +1956,6 @@ nfsmout: vrele(fromnd.ni_vp); vn_finished_write(mp); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -2082,12 +1980,9 @@ nfsrv_link(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, nfsfh_t nfh, dnfh; fhandle_t *fhp, *dfhp; struct mount *mp = NULL; - int tvfslocked; - int vfslocked; nfsdbprintf(("%s %d\n", __FILE__, __LINE__)); ndclear(&nd); - vfslocked = 0; fhp = &nfh.fh_generic; dfhp = &dnfh.fh_generic; @@ -2096,15 +1991,12 @@ nfsrv_link(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, error = ESTALE; goto ereply; } - vfslocked = VFS_LOCK_GIANT(mp); (void) vn_start_write(NULL, &mp, V_WAIT); vfs_rel(mp); /* The write holds a ref. */ nfsm_srvmtofh(dfhp); nfsm_srvnamesiz(len); - error = nfsrv_fhtovp(fhp, TRUE, &vp, &tvfslocked, nfsd, slp, - nam, &rdonly, TRUE); - vfslocked = nfsrv_lockedpair(vfslocked, tvfslocked); + error = nfsrv_fhtovp(fhp, TRUE, &vp, nfsd, slp, nam, &rdonly, TRUE); if (error) { nfsm_reply(NFSX_POSTOPATTR(v3) + NFSX_WCCDATA(v3)); if (v3) { @@ -2124,10 +2016,9 @@ nfsrv_link(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, VOP_UNLOCK(vp, 0); nd.ni_cnd.cn_cred = cred; nd.ni_cnd.cn_nameiop = CREATE; - nd.ni_cnd.cn_flags = LOCKPARENT | MPSAFE | MPSAFE; + nd.ni_cnd.cn_flags = LOCKPARENT; error = nfs_namei(&nd, nfsd, dfhp, len, slp, nam, &md, &dpos, &dirp, v3, &dirfor, &dirfor_ret, FALSE); - vfslocked = nfsrv_lockedpair_nd(vfslocked, &nd); if (dirp && !v3) { vrele(dirp); dirp = NULL; @@ -2205,7 +2096,6 @@ nfsmout: if (nd.ni_vp) vrele(nd.ni_vp); vn_finished_write(mp); - VFS_UNLOCK_GIANT(vfslocked); return(error); } @@ -2234,12 +2124,9 @@ nfsrv_symlink(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, nfsfh_t nfh; fhandle_t *fhp; struct mount *mp = NULL; - int tvfslocked; - int vfslocked; nfsdbprintf(("%s %d\n", __FILE__, __LINE__)); ndclear(&nd); - vfslocked = 0; fhp = &nfh.fh_generic; nfsm_srvmtofh(fhp); @@ -2247,16 +2134,14 @@ nfsrv_symlink(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, error = ESTALE; goto out; } - vfslocked = VFS_LOCK_GIANT(mp); (void) vn_start_write(NULL, &mp, V_WAIT); vfs_rel(mp); /* The write holds a ref. */ nfsm_srvnamesiz(len); nd.ni_cnd.cn_cred = cred; nd.ni_cnd.cn_nameiop = CREATE; - nd.ni_cnd.cn_flags = LOCKPARENT | SAVESTART | MPSAFE; + nd.ni_cnd.cn_flags = LOCKPARENT | SAVESTART; error = nfs_namei(&nd, nfsd, fhp, len, slp, nam, &md, &dpos, &dirp, v3, &dirfor, &dirfor_ret, FALSE); - vfslocked = nfsrv_lockedpair_nd(vfslocked, &nd); if (error == 0) { VATTR_NULL(vap); if (v3) @@ -2322,13 +2207,8 @@ nfsrv_symlink(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, nd.ni_cnd.cn_flags |= (NOFOLLOW | LOCKLEAF); nd.ni_cnd.cn_thread = curthread; nd.ni_cnd.cn_cred = cred; - tvfslocked = VFS_LOCK_GIANT(nd.ni_startdir->v_mount); - if (tvfslocked) - nd.ni_cnd.cn_flags |= GIANTHELD; error = lookup(&nd); nd.ni_dvp = NULL; - vfslocked = nfsrv_lockedpair_nd(vfslocked, &nd); - nd.ni_cnd.cn_flags &= ~GIANTHELD; if (error == 0) { bzero((caddr_t)fhp, sizeof(nfh)); @@ -2388,7 +2268,6 @@ nfsmout: free(pathcp, M_TEMP); vn_finished_write(mp); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -2417,11 +2296,9 @@ nfsrv_mkdir(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, nfsfh_t nfh; fhandle_t *fhp; struct mount *mp = NULL; - int vfslocked; nfsdbprintf(("%s %d\n", __FILE__, __LINE__)); ndclear(&nd); - vfslocked = 0; fhp = &nfh.fh_generic; nfsm_srvmtofh(fhp); @@ -2429,17 +2306,15 @@ nfsrv_mkdir(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, error = ESTALE; goto out; } - vfslocked = VFS_LOCK_GIANT(mp); (void) vn_start_write(NULL, &mp, V_WAIT); vfs_rel(mp); /* The write holds a ref. */ nfsm_srvnamesiz(len); nd.ni_cnd.cn_cred = cred; nd.ni_cnd.cn_nameiop = CREATE; - nd.ni_cnd.cn_flags = LOCKPARENT | MPSAFE; + nd.ni_cnd.cn_flags = LOCKPARENT; error = nfs_namei(&nd, nfsd, fhp, len, slp, nam, &md, &dpos, &dirp, v3, &dirfor, &dirfor_ret, FALSE); - vfslocked = nfsrv_lockedpair_nd(vfslocked, &nd); if (dirp && !v3) { vrele(dirp); dirp = NULL; @@ -2551,7 +2426,6 @@ nfsmout: if (dirp) vrele(dirp); vn_finished_write(mp); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -2576,11 +2450,9 @@ nfsrv_rmdir(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, fhandle_t *fhp; struct nameidata nd; struct mount *mp = NULL; - int vfslocked; nfsdbprintf(("%s %d\n", __FILE__, __LINE__)); ndclear(&nd); - vfslocked = 0; fhp = &nfh.fh_generic; nfsm_srvmtofh(fhp); @@ -2588,16 +2460,14 @@ nfsrv_rmdir(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, error = ESTALE; goto out; } - vfslocked = VFS_LOCK_GIANT(mp); (void) vn_start_write(NULL, &mp, V_WAIT); vfs_rel(mp); /* The write holds a ref. */ nfsm_srvnamesiz(len); nd.ni_cnd.cn_cred = cred; nd.ni_cnd.cn_nameiop = DELETE; - nd.ni_cnd.cn_flags = LOCKPARENT | LOCKLEAF | MPSAFE; + nd.ni_cnd.cn_flags = LOCKPARENT | LOCKLEAF; error = nfs_namei(&nd, nfsd, fhp, len, slp, nam, &md, &dpos, &dirp, v3, &dirfor, &dirfor_ret, FALSE); - vfslocked = nfsrv_lockedpair_nd(vfslocked, &nd); if (dirp && !v3) { vrele(dirp); dirp = NULL; @@ -2675,7 +2545,6 @@ nfsmout: vrele(dirp); vn_finished_write(mp); - VFS_UNLOCK_GIANT(vfslocked); return(error); } @@ -2744,10 +2613,8 @@ nfsrv_readdir(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, int v3 = (nfsd->nd_flag & ND_NFSV3); u_quad_t off, toff, verf; u_long *cookies = NULL, *cookiep; /* needs to be int64_t or off_t */ - int vfslocked; nfsdbprintf(("%s %d\n", __FILE__, __LINE__)); - vfslocked = 0; fhp = &nfh.fh_generic; nfsm_srvmtofh(fhp); if (v3) { @@ -2770,8 +2637,7 @@ nfsrv_readdir(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, if (siz > xfer) siz = xfer; fullsiz = siz; - error = nfsrv_fhtovp(fhp, 1, &vp, &vfslocked, nfsd, slp, - nam, &rdonly, TRUE); + error = nfsrv_fhtovp(fhp, 1, &vp, nfsd, slp, nam, &rdonly, TRUE); if (!error && vp->v_type != VDIR) { error = ENOTDIR; vput(vp); @@ -3008,7 +2874,6 @@ again: nfsmout: if (vp) vrele(vp); - VFS_UNLOCK_GIANT(vfslocked); return(error); } @@ -3041,10 +2906,8 @@ nfsrv_readdirplus(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, u_quad_t off, toff, verf; u_long *cookies = NULL, *cookiep; /* needs to be int64_t or off_t */ int v3 = (nfsd->nd_flag & ND_NFSV3); - int vfslocked; nfsdbprintf(("%s %d\n", __FILE__, __LINE__)); - vfslocked = 0; if (!v3) panic("nfsrv_readdirplus: v3 proc called on a v2 connection"); fhp = &nfh.fh_generic; @@ -3064,8 +2927,7 @@ nfsrv_readdirplus(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, if (siz > xfer) siz = xfer; fullsiz = siz; - error = nfsrv_fhtovp(fhp, 1, &vp, &vfslocked, nfsd, slp, - nam, &rdonly, TRUE); + error = nfsrv_fhtovp(fhp, 1, &vp, nfsd, slp, nam, &rdonly, TRUE); if (!error && vp->v_type != VDIR) { error = ENOTDIR; vput(vp); @@ -3357,7 +3219,6 @@ invalid: nfsmout: if (vp) vrele(vp); - VFS_UNLOCK_GIANT(vfslocked); return(error); } @@ -3383,11 +3244,8 @@ nfsrv_commit(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, u_quad_t off; struct mount *mp = NULL; int v3 = (nfsd->nd_flag & ND_NFSV3); - int tvfslocked; - int vfslocked; nfsdbprintf(("%s %d\n", __FILE__, __LINE__)); - vfslocked = 0; if (!v3) panic("nfsrv_commit: v3 proc called on a v2 connection"); fhp = &nfh.fh_generic; @@ -3396,7 +3254,6 @@ nfsrv_commit(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, error = ESTALE; goto ereply; } - vfslocked = VFS_LOCK_GIANT(mp); (void) vn_start_write(NULL, &mp, V_WAIT); vfs_rel(mp); /* The write holds a ref. */ tl = nfsm_dissect_nonblock(u_int32_t *, 3 * NFSX_UNSIGNED); @@ -3408,9 +3265,7 @@ nfsrv_commit(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, off = fxdr_hyper(tl); tl += 2; cnt = fxdr_unsigned(int, *tl); - error = nfsrv_fhtovp(fhp, 1, &vp, &tvfslocked, nfsd, slp, - nam, &rdonly, TRUE); - vfslocked = nfsrv_lockedpair(vfslocked, tvfslocked); + error = nfsrv_fhtovp(fhp, 1, &vp, nfsd, slp, nam, &rdonly, TRUE); if (error) { nfsm_reply(2 * NFSX_UNSIGNED); nfsm_srvwcc_data(for_ret, &bfor, aft_ret, &aft); @@ -3520,7 +3375,6 @@ nfsmout: if (vp) vput(vp); vn_finished_write(mp); - VFS_UNLOCK_GIANT(vfslocked); return(error); } @@ -3547,14 +3401,11 @@ nfsrv_statfs(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, fhandle_t *fhp; struct statfs statfs; u_quad_t tval; - int vfslocked; nfsdbprintf(("%s %d\n", __FILE__, __LINE__)); - vfslocked = 0; fhp = &nfh.fh_generic; nfsm_srvmtofh(fhp); - error = nfsrv_fhtovp(fhp, 1, &vp, &vfslocked, nfsd, slp, - nam, &rdonly, TRUE); + error = nfsrv_fhtovp(fhp, 1, &vp, nfsd, slp, nam, &rdonly, TRUE); if (error) { nfsm_reply(NFSX_UNSIGNED); if (v3) @@ -3614,7 +3465,6 @@ nfsrv_statfs(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, nfsmout: if (vp) vput(vp); - VFS_UNLOCK_GIANT(vfslocked); return(error); } @@ -3640,16 +3490,13 @@ nfsrv_fsinfo(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, u_quad_t maxfsize; struct statfs sb; int v3 = (nfsd->nd_flag & ND_NFSV3); - int vfslocked; nfsdbprintf(("%s %d\n", __FILE__, __LINE__)); if (!v3) panic("nfsrv_fsinfo: v3 proc called on a v2 connection"); fhp = &nfh.fh_generic; - vfslocked = 0; nfsm_srvmtofh(fhp); - error = nfsrv_fhtovp(fhp, 1, &vp, &vfslocked, nfsd, slp, - nam, &rdonly, TRUE); + error = nfsrv_fhtovp(fhp, 1, &vp, nfsd, slp, nam, &rdonly, TRUE); if (error) { nfsm_reply(NFSX_UNSIGNED); nfsm_srvpostop_attr(getret, &at); @@ -3690,7 +3537,6 @@ nfsrv_fsinfo(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, nfsmout: if (vp) vput(vp); - VFS_UNLOCK_GIANT(vfslocked); return(error); } @@ -3715,16 +3561,13 @@ nfsrv_pathconf(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, nfsfh_t nfh; fhandle_t *fhp; int v3 = (nfsd->nd_flag & ND_NFSV3); - int vfslocked; nfsdbprintf(("%s %d\n", __FILE__, __LINE__)); if (!v3) panic("nfsrv_pathconf: v3 proc called on a v2 connection"); - vfslocked = 0; fhp = &nfh.fh_generic; nfsm_srvmtofh(fhp); - error = nfsrv_fhtovp(fhp, 1, &vp, &vfslocked, nfsd, slp, - nam, &rdonly, TRUE); + error = nfsrv_fhtovp(fhp, 1, &vp, nfsd, slp, nam, &rdonly, TRUE); if (error) { nfsm_reply(NFSX_UNSIGNED); nfsm_srvpostop_attr(getret, &at); @@ -3764,7 +3607,6 @@ nfsrv_pathconf(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, nfsmout: if (vp) vput(vp); - VFS_UNLOCK_GIANT(vfslocked); return(error); } @@ -3833,8 +3675,6 @@ nfsrv_access(struct vnode *vp, accmode_t accmode, struct ucred *cred, struct vattr vattr; int error; - VFS_ASSERT_GIANT(vp->v_mount); - nfsdbprintf(("%s %d\n", __FILE__, __LINE__)); if (accmode & VWRITE) { diff --git a/sys/nfsserver/nfs_srvsubs.c b/sys/nfsserver/nfs_srvsubs.c index ee0614b..865444d 100644 --- a/sys/nfsserver/nfs_srvsubs.c +++ b/sys/nfsserver/nfs_srvsubs.c @@ -593,11 +593,7 @@ nfs_namei(struct nameidata *ndp, struct nfsrv_descript *nfsd, int error, rdonly, linklen; struct componentname *cnp = &ndp->ni_cnd; int lockleaf = (cnp->cn_flags & LOCKLEAF) != 0; - int dvfslocked; - int vfslocked; - vfslocked = 0; - dvfslocked = 0; *retdirp = NULL; cnp->cn_flags |= NOMACCHECK; cnp->cn_pnbuf = uma_zalloc(namei_zone, M_WAITOK); @@ -641,11 +637,7 @@ nfs_namei(struct nameidata *ndp, struct nfsrv_descript *nfsd, /* * Extract and set starting directory. */ - error = nfsrv_fhtovp(fhp, FALSE, &dp, &dvfslocked, - nfsd, slp, nam, &rdonly, pubflag); - if (error) - goto out; - vfslocked = VFS_LOCK_GIANT(dp->v_mount); + error = nfsrv_fhtovp(fhp, FALSE, &dp, nfsd, slp, nam, &rdonly, pubflag); if (dp->v_type != VDIR) { vrele(dp); error = ENOTDIR; @@ -663,7 +655,7 @@ nfs_namei(struct nameidata *ndp, struct nfsrv_descript *nfsd, if (v3) { vn_lock(dp, LK_EXCLUSIVE | LK_RETRY); *retdirattr_retp = VOP_GETATTR(dp, retdirattrp, - ndp->ni_cnd.cn_cred); + ndp->ni_cnd.cn_cred); VOP_UNLOCK(dp, 0); } @@ -723,14 +715,9 @@ nfs_namei(struct nameidata *ndp, struct nfsrv_descript *nfsd, if (pubflag) { ndp->ni_rootdir = rootvnode; ndp->ni_loopcnt = 0; - if (cnp->cn_pnbuf[0] == '/') { - int tvfslocked; - tvfslocked = VFS_LOCK_GIANT(rootvnode->v_mount); - VFS_UNLOCK_GIANT(vfslocked); + if (cnp->cn_pnbuf[0] == '/') dp = rootvnode; - vfslocked = tvfslocked; - } } else { cnp->cn_flags |= NOCROSSMOUNT; } @@ -755,11 +742,7 @@ nfs_namei(struct nameidata *ndp, struct nfsrv_descript *nfsd, * In either case ni_startdir will be dereferenced and NULLed * out. */ - if (vfslocked) - ndp->ni_cnd.cn_flags |= GIANTHELD; error = lookup(ndp); - vfslocked = (ndp->ni_cnd.cn_flags & GIANTHELD) != 0; - ndp->ni_cnd.cn_flags &= ~GIANTHELD; if (error) break; @@ -857,10 +840,6 @@ nfs_namei(struct nameidata *ndp, struct nfsrv_descript *nfsd, } if (!lockleaf) cnp->cn_flags &= ~LOCKLEAF; - if (cnp->cn_flags & GIANTHELD) { - mtx_unlock(&Giant); - cnp->cn_flags &= ~GIANTHELD; - } /* * nfs_namei() guarentees that fields will not contain garbage @@ -874,21 +853,9 @@ out: ndp->ni_dvp = NULL; ndp->ni_startdir = NULL; cnp->cn_flags &= ~HASBUF; - VFS_UNLOCK_GIANT(vfslocked); - vfslocked = 0; } else if ((ndp->ni_cnd.cn_flags & (WANTPARENT|LOCKPARENT)) == 0) { ndp->ni_dvp = NULL; } - /* - * This differs from normal namei() in that even on failure we may - * return with Giant held due to the dirp return. Make sure we only - * have not recursed however. The calling code only expects to drop - * one acquire. - */ - if (vfslocked || dvfslocked) - ndp->ni_cnd.cn_flags |= GIANTHELD; - if (vfslocked && dvfslocked) - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -1053,7 +1020,7 @@ nfsm_srvfattr(struct nfsrv_descript *nfsd, struct vattr *vap, * - if not lockflag unlock it with VOP_UNLOCK() */ int -nfsrv_fhtovp(fhandle_t *fhp, int lockflag, struct vnode **vpp, int *vfslockedp, +nfsrv_fhtovp(fhandle_t *fhp, int lockflag, struct vnode **vpp, struct nfsrv_descript *nfsd, struct nfssvc_sock *slp, struct sockaddr *nam, int *rdonlyp, int pubflag) { @@ -1065,13 +1032,11 @@ nfsrv_fhtovp(fhandle_t *fhp, int lockflag, struct vnode **vpp, int *vfslockedp, struct sockaddr_int *saddr; #endif int credflavor; - int vfslocked; int numsecflavors, *secflavors; int authsys; int v3 = nfsd->nd_flag & ND_NFSV3; int mountreq; - *vfslockedp = 0; *vpp = NULL; if (nfs_ispublicfh(fhp)) { @@ -1083,7 +1048,6 @@ nfsrv_fhtovp(fhandle_t *fhp, int lockflag, struct vnode **vpp, int *vfslockedp, mp = vfs_busyfs(&fhp->fh_fsid); if (!mp) return (ESTALE); - vfslocked = VFS_LOCK_GIANT(mp); error = VFS_CHECKEXP(mp, nam, &exflags, &credanon, &numsecflavors, &secflavors); if (error) { @@ -1162,10 +1126,6 @@ out: if (credanon != NULL) crfree(credanon); - if (error) { - VFS_UNLOCK_GIANT(vfslocked); - } else - *vfslockedp = vfslocked; return (error); } diff --git a/sys/nlm/nlm_prot_impl.c b/sys/nlm/nlm_prot_impl.c index f6b296d..0ee56b6 100644 --- a/sys/nlm/nlm_prot_impl.c +++ b/sys/nlm/nlm_prot_impl.c @@ -1769,7 +1769,6 @@ nlm_convert_to_fhandle_t(fhandle_t *fhp, struct netobj *p) struct vfs_state { struct mount *vs_mp; struct vnode *vs_vp; - int vs_vfslocked; int vs_vnlocked; }; @@ -1786,7 +1785,6 @@ nlm_get_vfs_state(struct nlm_host *host, struct svc_req *rqstp, if (!vs->vs_mp) { return (ESTALE); } - vs->vs_vfslocked = VFS_LOCK_GIANT(vs->vs_mp); error = VFS_CHECKEXP(vs->vs_mp, (struct sockaddr *)&host->nh_addr, &exflags, &credanon, NULL, NULL); @@ -1848,7 +1846,6 @@ nlm_release_vfs_state(struct vfs_state *vs) } if (vs->vs_mp) vfs_rel(vs->vs_mp); - VFS_UNLOCK_GIANT(vs->vs_vfslocked); } static nlm4_stats diff --git a/sys/security/audit/audit_arg.c b/sys/security/audit/audit_arg.c index 562b799..0ae6e8c 100644 --- a/sys/security/audit/audit_arg.c +++ b/sys/security/audit/audit_arg.c @@ -651,7 +651,6 @@ audit_arg_file(struct proc *p, struct file *fp) struct socket *so; struct inpcb *pcb; struct vnode *vp; - int vfslocked; ar = currecord(); if (ar == NULL) @@ -664,11 +663,9 @@ audit_arg_file(struct proc *p, struct file *fp) * XXXAUDIT: Only possibly to record as first vnode? */ vp = fp->f_vnode; - vfslocked = VFS_LOCK_GIANT(vp->v_mount); vn_lock(vp, LK_SHARED | LK_RETRY); audit_arg_vnode1(vp); VOP_UNLOCK(vp, 0); - VFS_UNLOCK_GIANT(vfslocked); break; case DTYPE_SOCKET: @@ -768,11 +765,6 @@ audit_arg_vnode(struct vnode *vp, struct vnode_au_info *vnp) struct vattr vattr; int error; - /* - * Assume that if the caller is calling audit_arg_vnode() on a - * non-MPSAFE vnode, then it will have acquired Giant. - */ - VFS_ASSERT_GIANT(vp->v_mount); ASSERT_VOP_LOCKED(vp, "audit_arg_vnode"); error = VOP_GETATTR(vp, &vattr, curthread->td_ucred); @@ -876,7 +868,6 @@ audit_sysclose(struct thread *td, int fd) struct kaudit_record *ar; struct vnode *vp; struct file *fp; - int vfslocked; KASSERT(td != NULL, ("audit_sysclose: td == NULL")); @@ -890,10 +881,8 @@ audit_sysclose(struct thread *td, int fd) return; vp = fp->f_vnode; - vfslocked = VFS_LOCK_GIANT(vp->v_mount); vn_lock(vp, LK_SHARED | LK_RETRY); audit_arg_vnode1(vp); VOP_UNLOCK(vp, 0); - VFS_UNLOCK_GIANT(vfslocked); fdrop(fp, td); } diff --git a/sys/security/audit/audit_syscalls.c b/sys/security/audit/audit_syscalls.c index 075aac5..b326563 100644 --- a/sys/security/audit/audit_syscalls.c +++ b/sys/security/audit/audit_syscalls.c @@ -749,7 +749,7 @@ auditctl(struct thread *td, struct auditctl_args *uap) struct ucred *cred; struct vnode *vp; int error = 0; - int flags, vfslocked; + int flags; if (jailed(td->td_ucred)) return (ENOSYS); @@ -770,20 +770,18 @@ auditctl(struct thread *td, struct auditctl_args *uap) if (uap->path == NULL) return (EINVAL); - NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | MPSAFE | AUDITVNODE1, + NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | AUDITVNODE1, UIO_USERSPACE, uap->path, td); flags = AUDIT_OPEN_FLAGS; error = vn_open(&nd, &flags, 0, NULL); if (error) return (error); - vfslocked = NDHASGIANT(&nd); vp = nd.ni_vp; #ifdef MAC error = mac_system_check_auditctl(td->td_ucred, vp); VOP_UNLOCK(vp, 0); if (error) { vn_close(vp, AUDIT_CLOSE_FLAGS, td->td_ucred, td); - VFS_UNLOCK_GIANT(vfslocked); return (error); } #else @@ -792,10 +790,8 @@ auditctl(struct thread *td, struct auditctl_args *uap) NDFREE(&nd, NDF_ONLY_PNBUF); if (vp->v_type != VREG) { vn_close(vp, AUDIT_CLOSE_FLAGS, td->td_ucred, td); - VFS_UNLOCK_GIANT(vfslocked); return (EINVAL); } - VFS_UNLOCK_GIANT(vfslocked); cred = td->td_ucred; crhold(cred); diff --git a/sys/security/audit/audit_worker.c b/sys/security/audit/audit_worker.c index 631b29f..d21ae18 100644 --- a/sys/security/audit/audit_worker.c +++ b/sys/security/audit/audit_worker.c @@ -113,7 +113,7 @@ audit_record_write(struct vnode *vp, struct ucred *cred, void *data, static struct timeval last_fail; static int cur_lowspace_trigger; struct statfs *mnt_stat; - int error, vfslocked; + int error; static int cur_fail; struct vattr vattr; long temp; @@ -124,7 +124,6 @@ audit_record_write(struct vnode *vp, struct ucred *cred, void *data, return; mnt_stat = &vp->v_mount->mnt_stat; - vfslocked = VFS_LOCK_GIANT(vp->v_mount); /* * First, gather statistics on the audit log file and file system so @@ -258,7 +257,6 @@ audit_record_write(struct vnode *vp, struct ucred *cred, void *data, } } - VFS_UNLOCK_GIANT(vfslocked); return; fail_enospc: @@ -289,7 +287,6 @@ fail: panic("audit_worker: write error %d\n", error); } else if (ppsratecheck(&last_fail, &cur_fail, 1)) printf("audit_worker: write error %d\n", error); - VFS_UNLOCK_GIANT(vfslocked); } /* @@ -451,7 +448,6 @@ audit_rotate_vnode(struct ucred *cred, struct vnode *vp) { struct ucred *old_audit_cred; struct vnode *old_audit_vp; - int vfslocked; KASSERT((cred != NULL && vp != NULL) || (cred == NULL && vp == NULL), ("audit_rotate_vnode: cred %p vp %p", cred, vp)); @@ -473,10 +469,8 @@ audit_rotate_vnode(struct ucred *cred, struct vnode *vp) * If there was an old vnode/credential, close and free. */ if (old_audit_vp != NULL) { - vfslocked = VFS_LOCK_GIANT(old_audit_vp->v_mount); vn_close(old_audit_vp, AUDIT_CLOSE_FLAGS, old_audit_cred, curthread); - VFS_UNLOCK_GIANT(vfslocked); crfree(old_audit_cred); } } diff --git a/sys/security/mac/mac_process.c b/sys/security/mac/mac_process.c index 5b692dd..68875f2 100644 --- a/sys/security/mac/mac_process.c +++ b/sys/security/mac/mac_process.c @@ -254,7 +254,7 @@ mac_proc_vm_revoke_recurse(struct thread *td, struct ucred *cred, struct vm_map *map) { vm_map_entry_t vme; - int vfslocked, result; + int result; vm_prot_t revokeperms; vm_object_t backing_object, object; vm_ooffset_t offset; @@ -300,7 +300,6 @@ mac_proc_vm_revoke_recurse(struct thread *td, struct ucred *cred, if (object->type != OBJT_VNODE) continue; vp = (struct vnode *)object->handle; - vfslocked = VFS_LOCK_GIANT(vp->v_mount); vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); result = vme->max_protection; mac_vnode_check_mmap_downgrade(cred, vp, &result); @@ -310,10 +309,8 @@ mac_proc_vm_revoke_recurse(struct thread *td, struct ucred *cred, * but a policy needs to get removed. */ revokeperms = vme->max_protection & ~result; - if (!revokeperms) { - VFS_UNLOCK_GIANT(vfslocked); + if (!revokeperms) continue; - } printf("pid %ld: revoking %s perms from %#lx:%ld " "(max %s/cur %s)\n", (long)td->td_proc->p_pid, prot2str(revokeperms), (u_long)vme->start, @@ -372,7 +369,6 @@ mac_proc_vm_revoke_recurse(struct thread *td, struct ucred *cred, vme->protection & ~revokeperms); vm_map_simplify_entry(map, vme); } - VFS_UNLOCK_GIANT(vfslocked); } vm_map_unlock(map); } diff --git a/sys/security/mac/mac_syscalls.c b/sys/security/mac/mac_syscalls.c index 905c43b..69d6653 100644 --- a/sys/security/mac/mac_syscalls.c +++ b/sys/security/mac/mac_syscalls.c @@ -226,7 +226,7 @@ __mac_get_fd(struct thread *td, struct __mac_get_fd_args *uap) struct pipe *pipe; struct socket *so; short label_type; - int vfslocked, error; + int error; error = copyin(uap->mac_p, &mac, sizeof(mac)); if (error) @@ -256,11 +256,9 @@ __mac_get_fd(struct thread *td, struct __mac_get_fd_args *uap) return (EINVAL); vp = fp->f_vnode; intlabel = mac_vnode_label_alloc(); - vfslocked = VFS_LOCK_GIANT(vp->v_mount); vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); mac_vnode_copy_label(vp->v_label, intlabel); VOP_UNLOCK(vp, 0); - VFS_UNLOCK_GIANT(vfslocked); error = mac_vnode_externalize_label(intlabel, elements, buffer, mac.m_buflen); mac_vnode_label_free(intlabel); @@ -312,7 +310,7 @@ __mac_get_file(struct thread *td, struct __mac_get_file_args *uap) struct nameidata nd; struct label *intlabel; struct mac mac; - int vfslocked, error; + int error; if (!(mac_labeled & MPC_OBJECT_VNODE)) return (EINVAL); @@ -333,20 +331,18 @@ __mac_get_file(struct thread *td, struct __mac_get_file_args *uap) } buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO); - NDINIT(&nd, LOOKUP, MPSAFE | LOCKLEAF | FOLLOW, UIO_USERSPACE, + NDINIT(&nd, LOOKUP, LOCKLEAF | FOLLOW, UIO_USERSPACE, uap->path_p, td); error = namei(&nd); if (error) goto out; intlabel = mac_vnode_label_alloc(); - vfslocked = NDHASGIANT(&nd); mac_vnode_copy_label(nd.ni_vp->v_label, intlabel); error = mac_vnode_externalize_label(intlabel, elements, buffer, mac.m_buflen); NDFREE(&nd, 0); - VFS_UNLOCK_GIANT(vfslocked); mac_vnode_label_free(intlabel); if (error == 0) error = copyout(buffer, mac.m_string, strlen(buffer)+1); @@ -365,7 +361,7 @@ __mac_get_link(struct thread *td, struct __mac_get_link_args *uap) struct nameidata nd; struct label *intlabel; struct mac mac; - int vfslocked, error; + int error; if (!(mac_labeled & MPC_OBJECT_VNODE)) return (EINVAL); @@ -386,19 +382,17 @@ __mac_get_link(struct thread *td, struct __mac_get_link_args *uap) } buffer = malloc(mac.m_buflen, M_MACTEMP, M_WAITOK | M_ZERO); - NDINIT(&nd, LOOKUP, MPSAFE | LOCKLEAF | NOFOLLOW, UIO_USERSPACE, + NDINIT(&nd, LOOKUP, LOCKLEAF | NOFOLLOW, UIO_USERSPACE, uap->path_p, td); error = namei(&nd); if (error) goto out; intlabel = mac_vnode_label_alloc(); - vfslocked = NDHASGIANT(&nd); mac_vnode_copy_label(nd.ni_vp->v_label, intlabel); error = mac_vnode_externalize_label(intlabel, elements, buffer, mac.m_buflen); NDFREE(&nd, 0); - VFS_UNLOCK_GIANT(vfslocked); mac_vnode_label_free(intlabel); if (error == 0) @@ -422,7 +416,7 @@ __mac_set_fd(struct thread *td, struct __mac_set_fd_args *uap) struct vnode *vp; struct mac mac; char *buffer; - int error, vfslocked; + int error; error = copyin(uap->mac_p, &mac, sizeof(mac)); if (error) @@ -455,10 +449,8 @@ __mac_set_fd(struct thread *td, struct __mac_set_fd_args *uap) break; } vp = fp->f_vnode; - vfslocked = VFS_LOCK_GIANT(vp->v_mount); error = vn_start_write(vp, &mp, V_WAIT | PCATCH); if (error != 0) { - VFS_UNLOCK_GIANT(vfslocked); mac_vnode_label_free(intlabel); break; } @@ -466,7 +458,6 @@ __mac_set_fd(struct thread *td, struct __mac_set_fd_args *uap) error = vn_setlabel(vp, intlabel, td->td_ucred); VOP_UNLOCK(vp, 0); vn_finished_write(mp); - VFS_UNLOCK_GIANT(vfslocked); mac_vnode_label_free(intlabel); break; @@ -515,7 +506,7 @@ __mac_set_file(struct thread *td, struct __mac_set_file_args *uap) struct mount *mp; struct mac mac; char *buffer; - int vfslocked, error; + int error; if (!(mac_labeled & MPC_OBJECT_VNODE)) return (EINVAL); @@ -541,10 +532,9 @@ __mac_set_file(struct thread *td, struct __mac_set_file_args *uap) if (error) goto out; - NDINIT(&nd, LOOKUP, MPSAFE | LOCKLEAF | FOLLOW, UIO_USERSPACE, + NDINIT(&nd, LOOKUP, LOCKLEAF | FOLLOW, UIO_USERSPACE, uap->path_p, td); error = namei(&nd); - vfslocked = NDHASGIANT(&nd); if (error == 0) { error = vn_start_write(nd.ni_vp, &mp, V_WAIT | PCATCH); if (error == 0) { @@ -555,7 +545,6 @@ __mac_set_file(struct thread *td, struct __mac_set_file_args *uap) } NDFREE(&nd, 0); - VFS_UNLOCK_GIANT(vfslocked); out: mac_vnode_label_free(intlabel); return (error); @@ -569,7 +558,7 @@ __mac_set_link(struct thread *td, struct __mac_set_link_args *uap) struct mount *mp; struct mac mac; char *buffer; - int vfslocked, error; + int error; if (!(mac_labeled & MPC_OBJECT_VNODE)) return (EINVAL); @@ -595,10 +584,9 @@ __mac_set_link(struct thread *td, struct __mac_set_link_args *uap) if (error) goto out; - NDINIT(&nd, LOOKUP, MPSAFE | LOCKLEAF | NOFOLLOW, UIO_USERSPACE, + NDINIT(&nd, LOOKUP, LOCKLEAF | NOFOLLOW, UIO_USERSPACE, uap->path_p, td); error = namei(&nd); - vfslocked = NDHASGIANT(&nd); if (error == 0) { error = vn_start_write(nd.ni_vp, &mp, V_WAIT | PCATCH); if (error == 0) { @@ -609,7 +597,6 @@ __mac_set_link(struct thread *td, struct __mac_set_link_args *uap) } NDFREE(&nd, 0); - VFS_UNLOCK_GIANT(vfslocked); out: mac_vnode_label_free(intlabel); return (error); diff --git a/sys/sys/bufobj.h b/sys/sys/bufobj.h index 916b256..3934553 100644 --- a/sys/sys/bufobj.h +++ b/sys/sys/bufobj.h @@ -111,7 +111,6 @@ struct bufobj { */ #define BO_ONWORKLST (1 << 0) /* On syncer work-list */ #define BO_WWAIT (1 << 1) /* Wait for output to complete */ -#define BO_NEEDSGIANT (1 << 2) /* Require giant for child buffers. */ #define BO_MTX(bo) (&(bo)->bo_mtx) #define BO_LOCK(bo) mtx_lock(BO_MTX((bo))) diff --git a/sys/sys/mount.h b/sys/sys/mount.h index b826413..edba8a2 100644 --- a/sys/sys/mount.h +++ b/sys/sys/mount.h @@ -620,37 +620,6 @@ vfs_statfs_t __vfs_statfs; ({if (*(MP)->mnt_op->vfs_susp_clean != NULL) \ (*(MP)->mnt_op->vfs_susp_clean)(MP); }) -#define VFS_NEEDSGIANT_(MP) \ - ((MP) != NULL && ((MP)->mnt_kern_flag & MNTK_MPSAFE) == 0) - -#define VFS_NEEDSGIANT(MP) __extension__ \ -({ \ - struct mount *_mp; \ - _mp = (MP); \ - VFS_NEEDSGIANT_(_mp); \ -}) - -#define VFS_LOCK_GIANT(MP) __extension__ \ -({ \ - int _locked; \ - struct mount *_mp; \ - _mp = (MP); \ - if (VFS_NEEDSGIANT_(_mp)) { \ - mtx_lock(&Giant); \ - _locked = 1; \ - } else \ - _locked = 0; \ - _locked; \ -}) -#define VFS_UNLOCK_GIANT(locked) if ((locked)) mtx_unlock(&Giant); -#define VFS_ASSERT_GIANT(MP) do \ -{ \ - struct mount *_mp; \ - _mp = (MP); \ - if (VFS_NEEDSGIANT_(_mp)) \ - mtx_assert(&Giant, MA_OWNED); \ -} while (0) - #define VFS_KNOTE_LOCKED(vp, hint) do \ { \ if (((vp)->v_vflag & VV_NOKNOTE) == 0) \ diff --git a/sys/sys/namei.h b/sys/sys/namei.h index 716b38d..35968a2 100644 --- a/sys/sys/namei.h +++ b/sys/sys/namei.h @@ -138,15 +138,11 @@ struct nameidata { #define ISOPEN 0x00200000 /* caller is opening; return a real vnode. */ #define NOCROSSMOUNT 0x00400000 /* do not cross mount points */ #define NOMACCHECK 0x00800000 /* do not perform MAC checks */ -#define MPSAFE 0x01000000 /* namei() must acquire Giant if needed. */ -#define GIANTHELD 0x02000000 /* namei() is holding giant. */ #define AUDITVNODE1 0x04000000 /* audit the looked up vnode information */ #define AUDITVNODE2 0x08000000 /* audit the looked up vnode information */ #define TRAILINGSLASH 0x10000000 /* path ended in a slash */ #define PARAMASK 0x1ffffe00 /* mask of parameter descriptors */ -#define NDHASGIANT(NDP) (((NDP)->ni_cnd.cn_flags & GIANTHELD) != 0) - /* * Initialization of a nameidata structure. */ diff --git a/sys/ufs/ffs/ffs_alloc.c b/sys/ufs/ffs/ffs_alloc.c index 36952cc..0454b5b 100644 --- a/sys/ufs/ffs/ffs_alloc.c +++ b/sys/ufs/ffs/ffs_alloc.c @@ -2431,7 +2431,7 @@ sysctl_ffs_fsck(SYSCTL_HANDLER_ARGS) long blkcnt, blksize; struct filedesc *fdp; struct file *fp; - int vfslocked, filetype, error; + int filetype, error; if (req->newlen > sizeof cmd) return (EBADRPC); @@ -2636,23 +2636,18 @@ sysctl_ffs_fsck(SYSCTL_HANDLER_ARGS) #endif /* DEBUG */ if ((error = ffs_vget(mp, (ino_t)cmd.value, LK_SHARED, &vp))) break; - vfslocked = VFS_LOCK_GIANT(vp->v_mount); AUDIT_ARG_VNODE1(vp); if ((error = change_dir(vp, td)) != 0) { vput(vp); - VFS_UNLOCK_GIANT(vfslocked); break; } VOP_UNLOCK(vp, 0); - VFS_UNLOCK_GIANT(vfslocked); fdp = td->td_proc->p_fd; FILEDESC_XLOCK(fdp); vpold = fdp->fd_cdir; fdp->fd_cdir = vp; FILEDESC_XUNLOCK(fdp); - vfslocked = VFS_LOCK_GIANT(vpold->v_mount); vrele(vpold); - VFS_UNLOCK_GIANT(vfslocked); break; case FFS_SET_DOTDOT: diff --git a/sys/ufs/ffs/ffs_softdep.c b/sys/ufs/ffs/ffs_softdep.c index 4d652c1..1316f84 100644 --- a/sys/ufs/ffs/ffs_softdep.c +++ b/sys/ufs/ffs/ffs_softdep.c @@ -717,14 +717,12 @@ softdep_flush(void) struct ufsmount *ump; struct thread *td; int remaining; - int vfslocked; td = curthread; td->td_pflags |= TDP_NORUNNINGBUF; for (;;) { kproc_suspend_check(softdepproc); - vfslocked = VFS_LOCK_GIANT((struct mount *)NULL); ACQUIRE_LOCK(&lk); /* * If requested, try removing inode or removal dependencies. @@ -740,7 +738,6 @@ softdep_flush(void) wakeup_one(&proc_waiting); } FREE_LOCK(&lk); - VFS_UNLOCK_GIANT(vfslocked); remaining = 0; mtx_lock(&mountlist_mtx); for (mp = TAILQ_FIRST(&mountlist); mp != NULL; mp = nmp) { @@ -749,12 +746,10 @@ softdep_flush(void) continue; if (vfs_busy(mp, MBF_NOWAIT | MBF_MNTLSTLOCK)) continue; - vfslocked = VFS_LOCK_GIANT(mp); softdep_process_worklist(mp, 0); ump = VFSTOUFS(mp); remaining += ump->softdep_on_worklist - ump->softdep_on_worklist_inprogress; - VFS_UNLOCK_GIANT(vfslocked); mtx_lock(&mountlist_mtx); nmp = TAILQ_NEXT(mp, mnt_list); vfs_unbusy(mp); diff --git a/sys/ufs/ufs/ufs_quota.c b/sys/ufs/ufs/ufs_quota.c index 2db0444..c7b757c 100644 --- a/sys/ufs/ufs/ufs_quota.c +++ b/sys/ufs/ufs/ufs_quota.c @@ -489,7 +489,7 @@ quotaon(struct thread *td, struct mount *mp, int type, void *fname) struct vnode *vp, **vpp; struct vnode *mvp; struct dquot *dq; - int error, flags, vfslocked; + int error, flags; struct nameidata nd; error = priv_check(td, PRIV_UFS_QUOTAON); @@ -499,18 +499,16 @@ quotaon(struct thread *td, struct mount *mp, int type, void *fname) ump = VFSTOUFS(mp); dq = NODQUOT; - NDINIT(&nd, LOOKUP, FOLLOW | MPSAFE, UIO_USERSPACE, fname, td); + NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, fname, td); flags = FREAD | FWRITE; error = vn_open(&nd, &flags, 0, NULL); if (error) return (error); - vfslocked = NDHASGIANT(&nd); NDFREE(&nd, NDF_ONLY_PNBUF); vp = nd.ni_vp; VOP_UNLOCK(vp, 0); if (vp->v_type != VREG) { (void) vn_close(vp, FREAD|FWRITE, td->td_ucred, td); - VFS_UNLOCK_GIANT(vfslocked); return (EACCES); } @@ -518,7 +516,6 @@ quotaon(struct thread *td, struct mount *mp, int type, void *fname) if ((ump->um_qflags[type] & (QTF_OPENING|QTF_CLOSING)) != 0) { UFS_UNLOCK(ump); (void) vn_close(vp, FREAD|FWRITE, td->td_ucred, td); - VFS_UNLOCK_GIANT(vfslocked); return (EALREADY); } ump->um_qflags[type] |= QTF_OPENING|QTF_CLOSING; @@ -535,7 +532,6 @@ quotaon(struct thread *td, struct mount *mp, int type, void *fname) vp->v_vflag |= VV_SYSTEM; VOP_UNLOCK(vp, 0); *vpp = vp; - VFS_UNLOCK_GIANT(vfslocked); /* * Save the credential of the process that turned on quotas. * Set up the time limits for this quota. @@ -613,7 +609,6 @@ quotaoff1(struct thread *td, struct mount *mp, int type) struct dquot *dq; struct inode *ip; struct ucred *cr; - int vfslocked; int error; ump = VFSTOUFS(mp); @@ -666,12 +661,10 @@ again: ump->um_cred[type] = NOCRED; UFS_UNLOCK(ump); - vfslocked = VFS_LOCK_GIANT(qvp->v_mount); vn_lock(qvp, LK_EXCLUSIVE | LK_RETRY); qvp->v_vflag &= ~VV_SYSTEM; VOP_UNLOCK(qvp, 0); error = vn_close(qvp, FREAD|FWRITE, td->td_ucred, td); - VFS_UNLOCK_GIANT(vfslocked); crfree(cr); return (error); @@ -1037,7 +1030,7 @@ dqget(struct vnode *vp, u_long id, struct ufsmount *ump, int type, struct vnode *dqvp; struct iovec aiov; struct uio auio; - int vfslocked, dqvplocked, error; + int dqvplocked, error; #ifdef DEBUG_VFS_LOCKS if (vp != NULLVP) @@ -1083,12 +1076,10 @@ hfound: DQI_LOCK(dq); error = EIO; } *dqp = dq; - vfslocked = VFS_LOCK_GIANT(dqvp->v_mount); if (dqvplocked) vput(dqvp); else vrele(dqvp); - VFS_UNLOCK_GIANT(vfslocked); return (error); } @@ -1142,12 +1133,10 @@ hfound: DQI_LOCK(dq); DQH_UNLOCK(); tablefull("dquot"); *dqp = NODQUOT; - vfslocked = VFS_LOCK_GIANT(dqvp->v_mount); if (dqvplocked) vput(dqvp); else vrele(dqvp); - VFS_UNLOCK_GIANT(vfslocked); return (EUSERS); } if (dq->dq_cnt || (dq->dq_flags & DQ_MOD)) @@ -1179,7 +1168,6 @@ hfound: DQI_LOCK(dq); auio.uio_rw = UIO_READ; auio.uio_td = (struct thread *)0; - vfslocked = VFS_LOCK_GIANT(dqvp->v_mount); error = VOP_READ(dqvp, &auio, 0, ump->um_cred[type]); if (auio.uio_resid == sizeof(struct dqblk) && error == 0) bzero(&dq->dq_dqb, sizeof(struct dqblk)); @@ -1187,7 +1175,6 @@ hfound: DQI_LOCK(dq); vput(dqvp); else vrele(dqvp); - VFS_UNLOCK_GIANT(vfslocked); /* * I/O error in reading quota file, release * quota structure and reflect problem to caller. @@ -1296,7 +1283,7 @@ dqsync(struct vnode *vp, struct dquot *dq) struct vnode *dqvp; struct iovec aiov; struct uio auio; - int vfslocked, error; + int error; struct mount *mp; struct ufsmount *ump; @@ -1317,12 +1304,10 @@ dqsync(struct vnode *vp, struct dquot *dq) vref(dqvp); UFS_UNLOCK(ump); - vfslocked = VFS_LOCK_GIANT(dqvp->v_mount); DQI_LOCK(dq); if ((dq->dq_flags & DQ_MOD) == 0) { DQI_UNLOCK(dq); vrele(dqvp); - VFS_UNLOCK_GIANT(vfslocked); return (0); } DQI_UNLOCK(dq); @@ -1331,7 +1316,6 @@ dqsync(struct vnode *vp, struct dquot *dq) if (vp != dqvp) vn_lock(dqvp, LK_EXCLUSIVE | LK_RETRY); - VFS_UNLOCK_GIANT(vfslocked); DQI_LOCK(dq); DQI_WAIT(dq, PINOD+2, "dqsync"); if ((dq->dq_flags & DQ_MOD) == 0) @@ -1348,9 +1332,7 @@ dqsync(struct vnode *vp, struct dquot *dq) auio.uio_segflg = UIO_SYSSPACE; auio.uio_rw = UIO_WRITE; auio.uio_td = (struct thread *)0; - vfslocked = VFS_LOCK_GIANT(dqvp->v_mount); error = VOP_WRITE(dqvp, &auio, 0, dq->dq_ump->um_cred[dq->dq_type]); - VFS_UNLOCK_GIANT(vfslocked); if (auio.uio_resid && error == 0) error = EIO; @@ -1358,13 +1340,11 @@ dqsync(struct vnode *vp, struct dquot *dq) DQI_WAKEUP(dq); dq->dq_flags &= ~DQ_MOD; out: DQI_UNLOCK(dq); - vfslocked = VFS_LOCK_GIANT(dqvp->v_mount); if (vp != dqvp) vput(dqvp); else vrele(dqvp); vn_finished_secondary_write(mp); - VFS_UNLOCK_GIANT(vfslocked); return (error); } diff --git a/sys/vm/vm_contig.c b/sys/vm/vm_contig.c index 7358cb0..ebf6538 100644 --- a/sys/vm/vm_contig.c +++ b/sys/vm/vm_contig.c @@ -94,7 +94,6 @@ vm_contig_launder_page(vm_page_t m, vm_page_t *next) vm_page_t m_tmp; struct vnode *vp; struct mount *mp; - int vfslocked; mtx_assert(&vm_page_queue_mtx, MA_OWNED); object = m->object; @@ -122,13 +121,11 @@ vm_contig_launder_page(vm_page_t m, vm_page_t *next) vm_object_reference_locked(object); VM_OBJECT_UNLOCK(object); (void) vn_start_write(vp, &mp, V_WAIT); - vfslocked = VFS_LOCK_GIANT(vp->v_mount); vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); VM_OBJECT_LOCK(object); vm_object_page_clean(object, 0, 0, OBJPC_SYNC); VM_OBJECT_UNLOCK(object); VOP_UNLOCK(vp, 0); - VFS_UNLOCK_GIANT(vfslocked); vm_object_deallocate(object); vn_finished_write(mp); vm_page_lock_queues(); diff --git a/sys/vm/vm_fault.c b/sys/vm/vm_fault.c index 0a5a412..9f26f41 100644 --- a/sys/vm/vm_fault.c +++ b/sys/vm/vm_fault.c @@ -98,8 +98,6 @@ __FBSDID("$FreeBSD$"); #include #include -#include /* XXX Temporary for VFS_LOCK_GIANT() */ - #define PFBAK 4 #define PFFOR 4 #define PAGEORDER_SIZE (PFBAK+PFFOR) @@ -129,7 +127,6 @@ struct faultstate { vm_map_entry_t entry; int lookup_still_valid; struct vnode *vp; - int vfslocked; }; static inline void @@ -174,8 +171,6 @@ unlock_and_deallocate(struct faultstate *fs) vput(fs->vp); fs->vp = NULL; } - VFS_UNLOCK_GIANT(fs->vfslocked); - fs->vfslocked = 0; } /* @@ -225,7 +220,6 @@ vm_fault(vm_map_t map, vm_offset_t vaddr, vm_prot_t fault_type, growstack = TRUE; PCPU_INC(cnt.v_vm_faults); fs.vp = NULL; - fs.vfslocked = 0; faultcount = behind = 0; RetryFault:; @@ -499,7 +493,6 @@ readrest: */ unlock_map(&fs); -vnode_lock: if (fs.object->type == OBJT_VNODE) { vp = fs.object->handle; if (vp == fs.vp) @@ -510,25 +503,12 @@ vnode_lock: } locked = VOP_ISLOCKED(vp); - if (VFS_NEEDSGIANT(vp->v_mount) && !fs.vfslocked) { - fs.vfslocked = 1; - if (!mtx_trylock(&Giant)) { - VM_OBJECT_UNLOCK(fs.object); - mtx_lock(&Giant); - VM_OBJECT_LOCK(fs.object); - goto vnode_lock; - } - } if (locked != LK_EXCLUSIVE) locked = LK_SHARED; /* Do not sleep for vnode lock while fs.m is busy */ error = vget(vp, locked | LK_CANRECURSE | LK_NOWAIT, curthread); if (error != 0) { - int vfslocked; - - vfslocked = fs.vfslocked; - fs.vfslocked = 0; /* Keep Giant */ vhold(vp); release_page(&fs); unlock_and_deallocate(&fs); @@ -536,7 +516,6 @@ vnode_lock: LK_CANRECURSE, curthread); vdrop(vp); fs.vp = vp; - fs.vfslocked = vfslocked; KASSERT(error == 0, ("vm_fault: vget failed")); goto RetryFault; diff --git a/sys/vm/vm_mmap.c b/sys/vm/vm_mmap.c index 4963a60..b469dfc 100644 --- a/sys/vm/vm_mmap.c +++ b/sys/vm/vm_mmap.c @@ -1155,15 +1155,11 @@ vm_mmap_vnode(struct thread *td, vm_size_t objsize, struct mount *mp; struct ucred *cred; int error, flags; - int vfslocked; mp = vp->v_mount; cred = td->td_ucred; - vfslocked = VFS_LOCK_GIANT(mp); - if ((error = vget(vp, LK_SHARED, td)) != 0) { - VFS_UNLOCK_GIANT(vfslocked); + if ((error = vget(vp, LK_SHARED, td)) != 0) return (error); - } foff = *foffp; flags = *flagsp; obj = vp->v_object; @@ -1227,7 +1223,6 @@ mark_atime: done: vput(vp); - VFS_UNLOCK_GIANT(vfslocked); return (error); } diff --git a/sys/vm/vm_object.c b/sys/vm/vm_object.c index 399cb10..983fcdb 100644 --- a/sys/vm/vm_object.c +++ b/sys/vm/vm_object.c @@ -434,7 +434,6 @@ vm_object_vndeallocate(vm_object_t object) { struct vnode *vp = (struct vnode *) object->handle; - VFS_ASSERT_GIANT(vp->v_mount); VM_OBJECT_LOCK_ASSERT(object, MA_OWNED); KASSERT(object->type == OBJT_VNODE, ("vm_object_vndeallocate: not a vnode object")); @@ -475,38 +474,11 @@ vm_object_deallocate(vm_object_t object) vm_object_t temp; while (object != NULL) { - int vfslocked; - - vfslocked = 0; - restart: VM_OBJECT_LOCK(object); if (object->type == OBJT_VNODE) { - struct vnode *vp = (struct vnode *) object->handle; - - /* - * Conditionally acquire Giant for a vnode-backed - * object. We have to be careful since the type of - * a vnode object can change while the object is - * unlocked. - */ - if (VFS_NEEDSGIANT(vp->v_mount) && !vfslocked) { - vfslocked = 1; - if (!mtx_trylock(&Giant)) { - VM_OBJECT_UNLOCK(object); - mtx_lock(&Giant); - goto restart; - } - } vm_object_vndeallocate(object); - VFS_UNLOCK_GIANT(vfslocked); return; - } else - /* - * This is to handle the case that the object - * changed type while we dropped its lock to - * obtain Giant. - */ - VFS_UNLOCK_GIANT(vfslocked); + } KASSERT(object->ref_count != 0, ("vm_object_deallocate: object deallocated too many times: %d", object->type)); @@ -1081,11 +1053,9 @@ vm_object_sync(vm_object_t object, vm_ooffset_t offset, vm_size_t size, */ if (object->type == OBJT_VNODE && (object->flags & OBJ_MIGHTBEDIRTY) != 0) { - int vfslocked; vp = object->handle; VM_OBJECT_UNLOCK(object); (void) vn_start_write(vp, &mp, V_WAIT); - vfslocked = VFS_LOCK_GIANT(vp->v_mount); vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); flags = (syncio || invalidate) ? OBJPC_SYNC : 0; flags |= invalidate ? OBJPC_INVAL : 0; @@ -1096,7 +1066,6 @@ vm_object_sync(vm_object_t object, vm_ooffset_t offset, vm_size_t size, flags); VM_OBJECT_UNLOCK(object); VOP_UNLOCK(vp, 0); - VFS_UNLOCK_GIANT(vfslocked); vn_finished_write(mp); VM_OBJECT_LOCK(object); } diff --git a/sys/vm/vm_pageout.c b/sys/vm/vm_pageout.c index 723b14d..d71a040 100644 --- a/sys/vm/vm_pageout.c +++ b/sys/vm/vm_pageout.c @@ -885,7 +885,7 @@ rescan0: * pressure where there are insufficient clean pages * on the inactive queue, we may have to go all out. */ - int swap_pageouts_ok, vfslocked = 0; + int swap_pageouts_ok; struct vnode *vp = NULL; struct mount *mp = NULL; @@ -956,7 +956,6 @@ rescan0: vm_page_unlock_queues(); vm_object_reference_locked(object); VM_OBJECT_UNLOCK(object); - vfslocked = VFS_LOCK_GIANT(vp->v_mount); if (vget(vp, LK_EXCLUSIVE | LK_TIMELOCK, curthread)) { VM_OBJECT_LOCK(object); @@ -1025,7 +1024,6 @@ unlock_and_continue: vm_page_unlock_queues(); if (vp != NULL) vput(vp); - VFS_UNLOCK_GIANT(vfslocked); vm_object_deallocate(object); vn_finished_write(mp); vm_page_lock_queues(); diff --git a/sys/vm/vnode_pager.c b/sys/vm/vnode_pager.c index 179afbf..8fea854 100644 --- a/sys/vm/vnode_pager.c +++ b/sys/vm/vnode_pager.c @@ -288,7 +288,6 @@ vnode_pager_haspage(object, pindex, before, after) int poff; int bsize; int pagesperblock, blocksperpage; - int vfslocked; VM_OBJECT_LOCK_ASSERT(object, MA_OWNED); /* @@ -314,9 +313,7 @@ vnode_pager_haspage(object, pindex, before, after) reqblock = pindex * blocksperpage; } VM_OBJECT_UNLOCK(object); - vfslocked = VFS_LOCK_GIANT(vp->v_mount); err = VOP_BMAP(vp, reqblock, NULL, &bn, after, before); - VFS_UNLOCK_GIANT(vfslocked); VM_OBJECT_LOCK(object); if (err) return TRUE; @@ -659,15 +656,12 @@ vnode_pager_getpages(object, m, count, reqpage) int rtval; struct vnode *vp; int bytes = count * PAGE_SIZE; - int vfslocked; vp = object->handle; VM_OBJECT_UNLOCK(object); - vfslocked = VFS_LOCK_GIANT(vp->v_mount); rtval = VOP_GETPAGES(vp, m, bytes, reqpage, 0); KASSERT(rtval != EOPNOTSUPP, ("vnode_pager: FS getpages not implemented\n")); - VFS_UNLOCK_GIANT(vfslocked); VM_OBJECT_LOCK(object); return rtval; }