Deduplicate fsid comparisons
Comparing fsid_t objects requires internal knowledge of the fsid structure and yet this is duplicated across a number of places in the code. Simplify by creating a fsidcmp function (macro). Reviewed by: mjg, rmacklem Approved by: mav (mentor) MFC after: 1 week Sponsored by: iXsystems, Inc. Differential Revision: https://reviews.freebsd.org/D24749
This commit is contained in:
parent
49caa483b3
commit
245bfd34da
@ -334,9 +334,8 @@ bsde_rule_to_string(struct mac_bsdextended_rule *rule, char *buf, size_t buflen)
|
|||||||
if (rule->mbr_object.mbo_flags & MBO_FSID_DEFINED) {
|
if (rule->mbr_object.mbo_flags & MBO_FSID_DEFINED) {
|
||||||
numfs = getmntinfo(&mntbuf, MNT_NOWAIT);
|
numfs = getmntinfo(&mntbuf, MNT_NOWAIT);
|
||||||
for (i = 0; i < numfs; i++)
|
for (i = 0; i < numfs; i++)
|
||||||
if (memcmp(&(rule->mbr_object.mbo_fsid),
|
if (fsidcmp(&rule->mbr_object.mbo_fsid,
|
||||||
&(mntbuf[i].f_fsid),
|
&mntbuf[i].f_fsid) == 0)
|
||||||
sizeof(mntbuf[i].f_fsid)) == 0)
|
|
||||||
break;
|
break;
|
||||||
len = snprintf(cur, left, "filesys %s ",
|
len = snprintf(cur, left, "filesys %s ",
|
||||||
i == numfs ? "???" : mntbuf[i].f_mntonname);
|
i == numfs ? "???" : mntbuf[i].f_mntonname);
|
||||||
|
@ -81,8 +81,7 @@ issamefs(const char *path, struct statfs *stfsp)
|
|||||||
return (-1);
|
return (-1);
|
||||||
if (statfs(path, &stfsbuf) < 0)
|
if (statfs(path, &stfsbuf) < 0)
|
||||||
return (-1);
|
return (-1);
|
||||||
if ((stfsbuf.f_fsid.val[0] != stfsp->f_fsid.val[0]) ||
|
if (fsidcmp(&stfsbuf.f_fsid, &stfsp->f_fsid) != 0)
|
||||||
(stfsbuf.f_fsid.val[1] != stfsp->f_fsid.val[1]))
|
|
||||||
return (0);
|
return (0);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
@ -505,8 +505,7 @@ getmntentry(const char *fromname, const char *onname, fsid_t *fsid, dowhat what)
|
|||||||
continue;
|
continue;
|
||||||
if (onname != NULL && strcmp(sfs->f_mntonname, onname) != 0)
|
if (onname != NULL && strcmp(sfs->f_mntonname, onname) != 0)
|
||||||
continue;
|
continue;
|
||||||
if (fsid != NULL && bcmp(&sfs->f_fsid, fsid,
|
if (fsid != NULL && fsidcmp(&sfs->f_fsid, fsid) != 0)
|
||||||
sizeof(*fsid)) != 0)
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
switch (what) {
|
switch (what) {
|
||||||
|
@ -85,8 +85,7 @@ struct nfsexstuff {
|
|||||||
#define NFSVNO_SETEXRDONLY(e) ((e)->nes_exflag = (MNT_EXPORTED|MNT_EXRDONLY))
|
#define NFSVNO_SETEXRDONLY(e) ((e)->nes_exflag = (MNT_EXPORTED|MNT_EXRDONLY))
|
||||||
|
|
||||||
#define NFSVNO_CMPFH(f1, f2) \
|
#define NFSVNO_CMPFH(f1, f2) \
|
||||||
((f1)->fh_fsid.val[0] == (f2)->fh_fsid.val[0] && \
|
(fsidcmp(&(f1)->fh_fsid, &(f2)->fh_fsid) == 0 && \
|
||||||
(f1)->fh_fsid.val[1] == (f2)->fh_fsid.val[1] && \
|
|
||||||
bcmp(&(f1)->fh_fid, &(f2)->fh_fid, sizeof(struct fid)) == 0)
|
bcmp(&(f1)->fh_fid, &(f2)->fh_fid, sizeof(struct fid)) == 0)
|
||||||
|
|
||||||
#define NFSLOCKHASH(f) \
|
#define NFSLOCKHASH(f) \
|
||||||
|
@ -4019,11 +4019,8 @@ nfsrv_pnfscreate(struct vnode *vp, struct vattr *vap, struct ucred *cred,
|
|||||||
if (tds->nfsdev_nmp != NULL) {
|
if (tds->nfsdev_nmp != NULL) {
|
||||||
if (tds->nfsdev_mdsisset == 0 && ds == NULL)
|
if (tds->nfsdev_mdsisset == 0 && ds == NULL)
|
||||||
ds = tds;
|
ds = tds;
|
||||||
else if (tds->nfsdev_mdsisset != 0 &&
|
else if (tds->nfsdev_mdsisset != 0 && fsidcmp(
|
||||||
mp->mnt_stat.f_fsid.val[0] ==
|
&mp->mnt_stat.f_fsid, &tds->nfsdev_mdsfsid) == 0) {
|
||||||
tds->nfsdev_mdsfsid.val[0] &&
|
|
||||||
mp->mnt_stat.f_fsid.val[1] ==
|
|
||||||
tds->nfsdev_mdsfsid.val[1]) {
|
|
||||||
ds = fds = tds;
|
ds = fds = tds;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -4043,10 +4040,8 @@ nfsrv_pnfscreate(struct vnode *vp, struct vattr *vap, struct ucred *cred,
|
|||||||
if (tds->nfsdev_nmp != NULL &&
|
if (tds->nfsdev_nmp != NULL &&
|
||||||
((tds->nfsdev_mdsisset == 0 && fds == NULL) ||
|
((tds->nfsdev_mdsisset == 0 && fds == NULL) ||
|
||||||
(tds->nfsdev_mdsisset != 0 && fds != NULL &&
|
(tds->nfsdev_mdsisset != 0 && fds != NULL &&
|
||||||
mp->mnt_stat.f_fsid.val[0] ==
|
fsidcmp(&mp->mnt_stat.f_fsid,
|
||||||
tds->nfsdev_mdsfsid.val[0] &&
|
&tds->nfsdev_mdsfsid) == 0))) {
|
||||||
mp->mnt_stat.f_fsid.val[1] ==
|
|
||||||
tds->nfsdev_mdsfsid.val[1]))) {
|
|
||||||
dsdir[mirrorcnt] = i;
|
dsdir[mirrorcnt] = i;
|
||||||
dvp[mirrorcnt] = tds->nfsdev_dsdir[i];
|
dvp[mirrorcnt] = tds->nfsdev_dsdir[i];
|
||||||
mirrorcnt++;
|
mirrorcnt++;
|
||||||
@ -4778,10 +4773,8 @@ nfsrv_dsgetsockmnt(struct vnode *vp, int lktype, char *buf, int *buflenp,
|
|||||||
fndds->nfsdev_mdsisset == 0) ||
|
fndds->nfsdev_mdsisset == 0) ||
|
||||||
(tds->nfsdev_mdsisset != 0 &&
|
(tds->nfsdev_mdsisset != 0 &&
|
||||||
fndds->nfsdev_mdsisset != 0 &&
|
fndds->nfsdev_mdsisset != 0 &&
|
||||||
tds->nfsdev_mdsfsid.val[0] ==
|
fsidcmp(&tds->nfsdev_mdsfsid,
|
||||||
mp->mnt_stat.f_fsid.val[0] &&
|
&mp->mnt_stat.f_fsid) == 0))) {
|
||||||
tds->nfsdev_mdsfsid.val[1] ==
|
|
||||||
mp->mnt_stat.f_fsid.val[1]))) {
|
|
||||||
*newnmpp = tds->nfsdev_nmp;
|
*newnmpp = tds->nfsdev_nmp;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -5968,8 +5961,7 @@ nfsrv_pnfsstatfs(struct statfs *sf, struct mount *mp)
|
|||||||
/* First, search for matches for same file system. */
|
/* First, search for matches for same file system. */
|
||||||
TAILQ_FOREACH(ds, &nfsrv_devidhead, nfsdev_list) {
|
TAILQ_FOREACH(ds, &nfsrv_devidhead, nfsdev_list) {
|
||||||
if (ds->nfsdev_nmp != NULL && ds->nfsdev_mdsisset != 0 &&
|
if (ds->nfsdev_nmp != NULL && ds->nfsdev_mdsisset != 0 &&
|
||||||
ds->nfsdev_mdsfsid.val[0] == mp->mnt_stat.f_fsid.val[0] &&
|
fsidcmp(&ds->nfsdev_mdsfsid, &mp->mnt_stat.f_fsid) == 0) {
|
||||||
ds->nfsdev_mdsfsid.val[1] == mp->mnt_stat.f_fsid.val[1]) {
|
|
||||||
if (++i > nfsrv_devidcnt)
|
if (++i > nfsrv_devidcnt)
|
||||||
break;
|
break;
|
||||||
*tdvpp++ = ds->nfsdev_dvp;
|
*tdvpp++ = ds->nfsdev_dvp;
|
||||||
|
@ -1059,10 +1059,7 @@ nfsrvd_compound(struct nfsrv_descript *nd, int isdgram, u_char *tag,
|
|||||||
if (!error && !nd->nd_repstat) {
|
if (!error && !nd->nd_repstat) {
|
||||||
if (op == NFSV4OP_LOOKUP || op == NFSV4OP_LOOKUPP) {
|
if (op == NFSV4OP_LOOKUP || op == NFSV4OP_LOOKUPP) {
|
||||||
new_mp = nvp->v_mount;
|
new_mp = nvp->v_mount;
|
||||||
if (cur_fsid.val[0] !=
|
if (fsidcmp(&cur_fsid, &new_mp->mnt_stat.f_fsid) != 0) {
|
||||||
new_mp->mnt_stat.f_fsid.val[0] ||
|
|
||||||
cur_fsid.val[1] !=
|
|
||||||
new_mp->mnt_stat.f_fsid.val[1]) {
|
|
||||||
/* crossed a server mount point */
|
/* crossed a server mount point */
|
||||||
nd->nd_repstat = nfsvno_checkexp(new_mp,
|
nd->nd_repstat = nfsvno_checkexp(new_mp,
|
||||||
nd->nd_nam, &nes, &credanon);
|
nd->nd_nam, &nes, &credanon);
|
||||||
@ -1091,8 +1088,7 @@ nfsrvd_compound(struct nfsrv_descript *nd, int isdgram, u_char *tag,
|
|||||||
if (vp == NULL || savevp == NULL) {
|
if (vp == NULL || savevp == NULL) {
|
||||||
nd->nd_repstat = NFSERR_NOFILEHANDLE;
|
nd->nd_repstat = NFSERR_NOFILEHANDLE;
|
||||||
break;
|
break;
|
||||||
} else if (cur_fsid.val[0] != save_fsid.val[0] ||
|
} else if (fsidcmp(&cur_fsid, &save_fsid) != 0) {
|
||||||
cur_fsid.val[1] != save_fsid.val[1]) {
|
|
||||||
nd->nd_repstat = NFSERR_XDEV;
|
nd->nd_repstat = NFSERR_XDEV;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -7535,8 +7535,7 @@ nfsrv_freelayouts(nfsquad_t *clid, fsid_t *fs, int laytype, int iomode)
|
|||||||
TAILQ_FOREACH_SAFE(lyp, &lhyp->list, lay_list, nlyp) {
|
TAILQ_FOREACH_SAFE(lyp, &lhyp->list, lay_list, nlyp) {
|
||||||
if (clid->qval != lyp->lay_clientid.qval)
|
if (clid->qval != lyp->lay_clientid.qval)
|
||||||
continue;
|
continue;
|
||||||
if (fs != NULL && (fs->val[0] != lyp->lay_fsid.val[0] ||
|
if (fs != NULL && fsidcmp(fs, &lyp->lay_fsid) != 0)
|
||||||
fs->val[1] != lyp->lay_fsid.val[1]))
|
|
||||||
continue;
|
continue;
|
||||||
if (laytype != lyp->lay_type)
|
if (laytype != lyp->lay_type)
|
||||||
continue;
|
continue;
|
||||||
@ -7830,10 +7829,8 @@ nfsrv_delds(char *devid, NFSPROC_T *p)
|
|||||||
TAILQ_FOREACH(ds, &nfsrv_devidhead, nfsdev_list) {
|
TAILQ_FOREACH(ds, &nfsrv_devidhead, nfsdev_list) {
|
||||||
if (ds != fndds && ds->nfsdev_nmp != NULL &&
|
if (ds != fndds && ds->nfsdev_nmp != NULL &&
|
||||||
ds->nfsdev_mdsisset != 0 &&
|
ds->nfsdev_mdsisset != 0 &&
|
||||||
ds->nfsdev_mdsfsid.val[0] ==
|
fsidcmp(&ds->nfsdev_mdsfsid,
|
||||||
fndds->nfsdev_mdsfsid.val[0] &&
|
&fndds->nfsdev_mdsfsid) == 0) {
|
||||||
ds->nfsdev_mdsfsid.val[1] ==
|
|
||||||
fndds->nfsdev_mdsfsid.val[1]) {
|
|
||||||
fndmirror = 1;
|
fndmirror = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -8737,10 +8734,8 @@ nfsrv_findmirroredds(struct nfsmount *nmp)
|
|||||||
TAILQ_FOREACH(ds, &nfsrv_devidhead, nfsdev_list) {
|
TAILQ_FOREACH(ds, &nfsrv_devidhead, nfsdev_list) {
|
||||||
if (ds != fndds && ds->nfsdev_nmp != NULL &&
|
if (ds != fndds && ds->nfsdev_nmp != NULL &&
|
||||||
ds->nfsdev_mdsisset != 0 &&
|
ds->nfsdev_mdsisset != 0 &&
|
||||||
ds->nfsdev_mdsfsid.val[0] ==
|
fsidcmp(&ds->nfsdev_mdsfsid,
|
||||||
fndds->nfsdev_mdsfsid.val[0] &&
|
&fndds->nfsdev_mdsfsid) == 0) {
|
||||||
ds->nfsdev_mdsfsid.val[1] ==
|
|
||||||
fndds->nfsdev_mdsfsid.val[1]) {
|
|
||||||
fndmirror = 1;
|
fndmirror = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -841,8 +841,7 @@ vfs_getvfs(fsid_t *fsid)
|
|||||||
CTR2(KTR_VFS, "%s: fsid %p", __func__, fsid);
|
CTR2(KTR_VFS, "%s: fsid %p", __func__, fsid);
|
||||||
mtx_lock(&mountlist_mtx);
|
mtx_lock(&mountlist_mtx);
|
||||||
TAILQ_FOREACH(mp, &mountlist, mnt_list) {
|
TAILQ_FOREACH(mp, &mountlist, mnt_list) {
|
||||||
if (mp->mnt_stat.f_fsid.val[0] == fsid->val[0] &&
|
if (fsidcmp(&mp->mnt_stat.f_fsid, fsid) == 0) {
|
||||||
mp->mnt_stat.f_fsid.val[1] == fsid->val[1]) {
|
|
||||||
vfs_ref(mp);
|
vfs_ref(mp);
|
||||||
mtx_unlock(&mountlist_mtx);
|
mtx_unlock(&mountlist_mtx);
|
||||||
return (mp);
|
return (mp);
|
||||||
@ -877,16 +876,13 @@ vfs_busyfs(fsid_t *fsid)
|
|||||||
hash = fsid->val[0] ^ fsid->val[1];
|
hash = fsid->val[0] ^ fsid->val[1];
|
||||||
hash = (hash >> 16 ^ hash) & (FSID_CACHE_SIZE - 1);
|
hash = (hash >> 16 ^ hash) & (FSID_CACHE_SIZE - 1);
|
||||||
mp = cache[hash];
|
mp = cache[hash];
|
||||||
if (mp == NULL ||
|
if (mp == NULL || fsidcmp(&mp->mnt_stat.f_fsid, fsid) != 0)
|
||||||
mp->mnt_stat.f_fsid.val[0] != fsid->val[0] ||
|
|
||||||
mp->mnt_stat.f_fsid.val[1] != fsid->val[1])
|
|
||||||
goto slow;
|
goto slow;
|
||||||
if (vfs_busy(mp, 0) != 0) {
|
if (vfs_busy(mp, 0) != 0) {
|
||||||
cache[hash] = NULL;
|
cache[hash] = NULL;
|
||||||
goto slow;
|
goto slow;
|
||||||
}
|
}
|
||||||
if (mp->mnt_stat.f_fsid.val[0] == fsid->val[0] &&
|
if (fsidcmp(&mp->mnt_stat.f_fsid, fsid) == 0)
|
||||||
mp->mnt_stat.f_fsid.val[1] == fsid->val[1])
|
|
||||||
return (mp);
|
return (mp);
|
||||||
else
|
else
|
||||||
vfs_unbusy(mp);
|
vfs_unbusy(mp);
|
||||||
@ -894,8 +890,7 @@ vfs_busyfs(fsid_t *fsid)
|
|||||||
slow:
|
slow:
|
||||||
mtx_lock(&mountlist_mtx);
|
mtx_lock(&mountlist_mtx);
|
||||||
TAILQ_FOREACH(mp, &mountlist, mnt_list) {
|
TAILQ_FOREACH(mp, &mountlist, mnt_list) {
|
||||||
if (mp->mnt_stat.f_fsid.val[0] == fsid->val[0] &&
|
if (fsidcmp(&mp->mnt_stat.f_fsid, fsid) == 0) {
|
||||||
mp->mnt_stat.f_fsid.val[1] == fsid->val[1]) {
|
|
||||||
error = vfs_busy(mp, MBF_MNTLSTLOCK);
|
error = vfs_busy(mp, MBF_MNTLSTLOCK);
|
||||||
if (error) {
|
if (error) {
|
||||||
cache[hash] = NULL;
|
cache[hash] = NULL;
|
||||||
|
@ -302,9 +302,8 @@ ugidfw_rulecheck(struct mac_bsdextended_rule *rule,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (rule->mbr_object.mbo_flags & MBO_FSID_DEFINED) {
|
if (rule->mbr_object.mbo_flags & MBO_FSID_DEFINED) {
|
||||||
match = (bcmp(&(vp->v_mount->mnt_stat.f_fsid),
|
match = (fsidcmp(&vp->v_mount->mnt_stat.f_fsid,
|
||||||
&(rule->mbr_object.mbo_fsid),
|
&rule->mbr_object.mbo_fsid) == 0);
|
||||||
sizeof(rule->mbr_object.mbo_fsid)) == 0);
|
|
||||||
if (rule->mbr_object.mbo_neg & MBO_FSID_DEFINED)
|
if (rule->mbr_object.mbo_neg & MBO_FSID_DEFINED)
|
||||||
match = !match;
|
match = !match;
|
||||||
if (!match)
|
if (!match)
|
||||||
|
@ -101,7 +101,7 @@ struct mac_bsdextended_object {
|
|||||||
uid_t mbo_uid_max;
|
uid_t mbo_uid_max;
|
||||||
gid_t mbo_gid_min;
|
gid_t mbo_gid_min;
|
||||||
gid_t mbo_gid_max;
|
gid_t mbo_gid_max;
|
||||||
struct fsid mbo_fsid;
|
fsid_t mbo_fsid;
|
||||||
int mbo_type;
|
int mbo_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -52,6 +52,8 @@
|
|||||||
|
|
||||||
typedef struct fsid { int32_t val[2]; } fsid_t; /* filesystem id type */
|
typedef struct fsid { int32_t val[2]; } fsid_t; /* filesystem id type */
|
||||||
|
|
||||||
|
#define fsidcmp(a, b) memcmp((a), (b), sizeof(fsid_t))
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* File identifier.
|
* File identifier.
|
||||||
* These are unique per filesystem on a single machine.
|
* These are unique per filesystem on a single machine.
|
||||||
|
@ -67,8 +67,7 @@ automounted_find(fsid_t fsid)
|
|||||||
struct automounted_fs *af;
|
struct automounted_fs *af;
|
||||||
|
|
||||||
TAILQ_FOREACH(af, &automounted, af_next) {
|
TAILQ_FOREACH(af, &automounted, af_next) {
|
||||||
if (af->af_fsid.val[0] == fsid.val[0] &&
|
if (fsidcmp(&af->af_fsid, &fsid) == 0)
|
||||||
af->af_fsid.val[1] == fsid.val[1])
|
|
||||||
return (af);
|
return (af);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1568,10 +1568,8 @@ get_exportlist_one(int passno)
|
|||||||
ep = get_exp();
|
ep = get_exp();
|
||||||
} else {
|
} else {
|
||||||
if (ep) {
|
if (ep) {
|
||||||
if (ep->ex_fs.val[0] !=
|
if (fsidcmp(&ep->ex_fs, &fsb.f_fsid)
|
||||||
fsb.f_fsid.val[0] ||
|
!= 0) {
|
||||||
ep->ex_fs.val[1] !=
|
|
||||||
fsb.f_fsid.val[1]) {
|
|
||||||
getexp_err(ep, tgrp,
|
getexp_err(ep, tgrp,
|
||||||
"fsid mismatch");
|
"fsid mismatch");
|
||||||
goto nextline;
|
goto nextline;
|
||||||
@ -2088,8 +2086,7 @@ compare_nmount_exportlist(struct iovec *iov, int iovlen, char *errmsg)
|
|||||||
if ((oep->ex_flag & EX_DONE) == 0) {
|
if ((oep->ex_flag & EX_DONE) == 0) {
|
||||||
LOGDEBUG("not done delete=%s", oep->ex_fsdir);
|
LOGDEBUG("not done delete=%s", oep->ex_fsdir);
|
||||||
if (statfs(oep->ex_fsdir, &ofs) >= 0 &&
|
if (statfs(oep->ex_fsdir, &ofs) >= 0 &&
|
||||||
oep->ex_fs.val[0] == ofs.f_fsid.val[0] &&
|
fsidcmp(&oep->ex_fs, &ofs.f_fsid) == 0) {
|
||||||
oep->ex_fs.val[1] == ofs.f_fsid.val[1]) {
|
|
||||||
LOGDEBUG("do delete");
|
LOGDEBUG("do delete");
|
||||||
/*
|
/*
|
||||||
* Clear has_publicfh if if was set
|
* Clear has_publicfh if if was set
|
||||||
@ -2353,8 +2350,7 @@ ex_search(fsid_t *fsid, struct exportlisthead *exhp)
|
|||||||
|
|
||||||
i = EXPHASH(fsid);
|
i = EXPHASH(fsid);
|
||||||
SLIST_FOREACH(ep, &exhp[i], entries) {
|
SLIST_FOREACH(ep, &exhp[i], entries) {
|
||||||
if (ep->ex_fs.val[0] == fsid->val[0] &&
|
if (fsidcmp(&ep->ex_fs, fsid) == 0)
|
||||||
ep->ex_fs.val[1] == fsid->val[1])
|
|
||||||
return (ep);
|
return (ep);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3122,8 +3118,7 @@ do_mount(struct exportlist *ep, struct grouplist *grp, int exflags,
|
|||||||
* filesystem.
|
* filesystem.
|
||||||
*/
|
*/
|
||||||
if (statfs(dirp, &fsb1) != 0 ||
|
if (statfs(dirp, &fsb1) != 0 ||
|
||||||
bcmp(&fsb1.f_fsid, &fsb->f_fsid,
|
fsidcmp(&fsb1.f_fsid, &fsb->f_fsid) != 0) {
|
||||||
sizeof (fsb1.f_fsid)) != 0) {
|
|
||||||
*cp = savedc;
|
*cp = savedc;
|
||||||
syslog(LOG_ERR,
|
syslog(LOG_ERR,
|
||||||
"can't export %s %s", dirp,
|
"can't export %s %s", dirp,
|
||||||
|
Loading…
Reference in New Issue
Block a user