Switch compat_20_sys_getfsstat() to mountlist iterator.

This commit is contained in:
hannken 2017-04-13 09:41:28 +00:00
parent 233ee5301d
commit 8fd5bc95f8
1 changed files with 9 additions and 16 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: vfs_syscalls_20.c,v 1.39 2015/07/24 13:02:52 maxv Exp $ */
/* $NetBSD: vfs_syscalls_20.c,v 1.40 2017/04/13 09:41:28 hannken Exp $ */
/*
* Copyright (c) 1989, 1993
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls_20.c,v 1.39 2015/07/24 13:02:52 maxv Exp $");
__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls_20.c,v 1.40 2017/04/13 09:41:28 hannken Exp $");
#ifdef _KERNEL_OPT
#include "opt_compat_netbsd.h"
@ -203,7 +203,8 @@ compat_20_sys_getfsstat(struct lwp *l, const struct compat_20_sys_getfsstat_args
syscallarg(int) flags;
} */
int root = 0;
struct mount *mp, *nmp;
mount_iterator_t *iter;
struct mount *mp;
struct statvfs *sbuf;
struct statfs12 *sfsp;
size_t count, maxcount;
@ -212,30 +213,21 @@ compat_20_sys_getfsstat(struct lwp *l, const struct compat_20_sys_getfsstat_args
sbuf = malloc(sizeof(*sbuf), M_TEMP, M_WAITOK);
maxcount = (size_t)SCARG(uap, bufsize) / sizeof(struct statfs12);
sfsp = SCARG(uap, buf);
mutex_enter(&mountlist_lock);
count = 0;
for (mp = TAILQ_FIRST(&mountlist); mp != NULL; mp = nmp) {
if (vfs_busy(mp, &nmp)) {
continue;
}
mountlist_iterator_init(&iter);
while ((mp = mountlist_iterator_next(iter)) != NULL) {
if (sfsp && count < maxcount) {
error = dostatvfs(mp, sbuf, l, SCARG(uap, flags), 0);
if (error) {
vfs_unbusy(mp, false, &nmp);
if (error)
continue;
}
error = vfs2fs(sfsp, sbuf);
if (error) {
vfs_unbusy(mp, false, NULL);
if (error)
goto out;
}
sfsp++;
root |= strcmp(sbuf->f_mntonname, "/") == 0;
}
count++;
vfs_unbusy(mp, false, &nmp);
}
mutex_exit(&mountlist_lock);
if (root == 0 && l->l_proc->p_cwdi->cwdi_rdir) {
/*
* fake a root entry
@ -252,6 +244,7 @@ compat_20_sys_getfsstat(struct lwp *l, const struct compat_20_sys_getfsstat_args
else
*retval = count;
out:
mountlist_iterator_destroy(iter);
free(sbuf, M_TEMP);
return error;
}