1*b819cea2SGordon Ross /*
2*b819cea2SGordon Ross * This file and its contents are supplied under the terms of the
3*b819cea2SGordon Ross * Common Development and Distribution License ("CDDL"), version 1.0.
4*b819cea2SGordon Ross * You may only use this file in accordance with the terms of version
5*b819cea2SGordon Ross * 1.0 of the CDDL.
6*b819cea2SGordon Ross *
7*b819cea2SGordon Ross * A full copy of the text of the CDDL should have accompanied this
8*b819cea2SGordon Ross * source. A copy of the CDDL is also available via the Internet at
9*b819cea2SGordon Ross * http://www.illumos.org/license/CDDL.
10*b819cea2SGordon Ross */
11*b819cea2SGordon Ross
12*b819cea2SGordon Ross /*
13*b819cea2SGordon Ross * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
14*b819cea2SGordon Ross */
15*b819cea2SGordon Ross
16*b819cea2SGordon Ross #include <sys/types.h>
17*b819cea2SGordon Ross #include <sys/param.h>
18*b819cea2SGordon Ross #include <sys/t_lock.h>
19*b819cea2SGordon Ross #include <sys/errno.h>
20*b819cea2SGordon Ross #include <sys/cred.h>
21*b819cea2SGordon Ross #include <sys/user.h>
22*b819cea2SGordon Ross #include <sys/uio.h>
23*b819cea2SGordon Ross #include <sys/file.h>
24*b819cea2SGordon Ross #include <sys/pathname.h>
25*b819cea2SGordon Ross #include <sys/vfs.h>
26*b819cea2SGordon Ross #include <sys/vnode.h>
27*b819cea2SGordon Ross #include <sys/stat.h>
28*b819cea2SGordon Ross #include <sys/mode.h>
29*b819cea2SGordon Ross #include <sys/conf.h>
30*b819cea2SGordon Ross #include <sys/sysmacros.h>
31*b819cea2SGordon Ross #include <sys/cmn_err.h>
32*b819cea2SGordon Ross #include <sys/systm.h>
33*b819cea2SGordon Ross #include <sys/kmem.h>
34*b819cea2SGordon Ross #include <sys/debug.h>
35*b819cea2SGordon Ross #include <sys/acl.h>
36*b819cea2SGordon Ross #include <sys/nbmlock.h>
37*b819cea2SGordon Ross #include <sys/fcntl.h>
38*b819cea2SGordon Ross #include <sys/poll.h>
39*b819cea2SGordon Ross
40*b819cea2SGordon Ross #include <errno.h>
41*b819cea2SGordon Ross #include <fcntl.h>
42*b819cea2SGordon Ross #include <unistd.h>
43*b819cea2SGordon Ross
44*b819cea2SGordon Ross #include "vncache.h"
45*b819cea2SGordon Ross
46*b819cea2SGordon Ross #define VFTBITS(feature) ((feature) & 0xFFFFFFFFLL)
47*b819cea2SGordon Ross
48*b819cea2SGordon Ross static uint64_t vfs_features = VFSFT_XVATTR;
49*b819cea2SGordon Ross
50*b819cea2SGordon Ross vnode_t *rootdir = NULL; /* pointer to root inode vnode. */
51*b819cea2SGordon Ross
52*b819cea2SGordon Ross static struct vfs fake_rootvfs;
53*b819cea2SGordon Ross struct vfs *rootvfs = NULL;
54*b819cea2SGordon Ross
55*b819cea2SGordon Ross int
fksmbsrv_vfs_init(void)56*b819cea2SGordon Ross fksmbsrv_vfs_init(void)
57*b819cea2SGordon Ross {
58*b819cea2SGordon Ross struct stat st;
59*b819cea2SGordon Ross int err, fd;
60*b819cea2SGordon Ross vnode_t *vp;
61*b819cea2SGordon Ross char *name = "/";
62*b819cea2SGordon Ross
63*b819cea2SGordon Ross if (rootvfs == NULL) {
64*b819cea2SGordon Ross rootvfs = &fake_rootvfs;
65*b819cea2SGordon Ross rootvfs->vfs_mntpt = refstr_alloc(name);
66*b819cea2SGordon Ross rootvfs->vfs_fsid.val[0] = 1;
67*b819cea2SGordon Ross }
68*b819cea2SGordon Ross
69*b819cea2SGordon Ross if (rootdir == NULL) {
70*b819cea2SGordon Ross if (lstat(name, &st) == -1)
71*b819cea2SGordon Ross return (errno);
72*b819cea2SGordon Ross fd = open(name, O_RDONLY, 0);
73*b819cea2SGordon Ross if (fd < 0) {
74*b819cea2SGordon Ross return (errno);
75*b819cea2SGordon Ross }
76*b819cea2SGordon Ross if (fstat(fd, &st) == -1) {
77*b819cea2SGordon Ross err = errno;
78*b819cea2SGordon Ross (void) close(fd);
79*b819cea2SGordon Ross return (err);
80*b819cea2SGordon Ross }
81*b819cea2SGordon Ross vp = vncache_enter(&st, NULL, "", fd);
82*b819cea2SGordon Ross /* extra hold for rootvp */
83*b819cea2SGordon Ross vn_hold(vp);
84*b819cea2SGordon Ross rootdir = vp;
85*b819cea2SGordon Ross
86*b819cea2SGordon Ross /* VFS stuff in global zone struct. */
87*b819cea2SGordon Ross zone0.zone_rootvp = rootdir;
88*b819cea2SGordon Ross zone0.zone_rootpath = "/";
89*b819cea2SGordon Ross }
90*b819cea2SGordon Ross
91*b819cea2SGordon Ross return (0);
92*b819cea2SGordon Ross
93*b819cea2SGordon Ross }
94*b819cea2SGordon Ross
95*b819cea2SGordon Ross
96*b819cea2SGordon Ross /*
97*b819cea2SGordon Ross * Query a vfs for a feature.
98*b819cea2SGordon Ross * Returns 1 if feature is present, 0 if not
99*b819cea2SGordon Ross */
100*b819cea2SGordon Ross /* ARGSUSED */
101*b819cea2SGordon Ross int
vfs_has_feature(vfs_t * vfsp,vfs_feature_t feature)102*b819cea2SGordon Ross vfs_has_feature(vfs_t *vfsp, vfs_feature_t feature)
103*b819cea2SGordon Ross {
104*b819cea2SGordon Ross int ret = 0;
105*b819cea2SGordon Ross
106*b819cea2SGordon Ross if (vfs_features & VFTBITS(feature))
107*b819cea2SGordon Ross ret = 1;
108*b819cea2SGordon Ross
109*b819cea2SGordon Ross return (ret);
110*b819cea2SGordon Ross }
111*b819cea2SGordon Ross
112*b819cea2SGordon Ross /* ARGSUSED */
113*b819cea2SGordon Ross struct vfs *
getvfs(fsid_t * fsid)114*b819cea2SGordon Ross getvfs(fsid_t *fsid)
115*b819cea2SGordon Ross {
116*b819cea2SGordon Ross return (rootvfs);
117*b819cea2SGordon Ross }
118*b819cea2SGordon Ross
119*b819cea2SGordon Ross vfsops_t *
vfs_getops(vfs_t * vfsp)120*b819cea2SGordon Ross vfs_getops(vfs_t *vfsp)
121*b819cea2SGordon Ross {
122*b819cea2SGordon Ross return (vfsp->vfs_op);
123*b819cea2SGordon Ross }
124*b819cea2SGordon Ross
125*b819cea2SGordon Ross /* ARGSUSED */
126*b819cea2SGordon Ross struct vfssw *
vfs_getvfsswbyvfsops(vfsops_t * vfsops)127*b819cea2SGordon Ross vfs_getvfsswbyvfsops(vfsops_t *vfsops)
128*b819cea2SGordon Ross {
129*b819cea2SGordon Ross return (NULL);
130*b819cea2SGordon Ross }
131*b819cea2SGordon Ross
132*b819cea2SGordon Ross /* ARGSUSED */
133*b819cea2SGordon Ross void
vfs_unrefvfssw(struct vfssw * vswp)134*b819cea2SGordon Ross vfs_unrefvfssw(struct vfssw *vswp)
135*b819cea2SGordon Ross {
136*b819cea2SGordon Ross }
137*b819cea2SGordon Ross
138*b819cea2SGordon Ross /* ARGSUSED */
139*b819cea2SGordon Ross int
fsop_root(vfs_t * vfsp,vnode_t ** vpp)140*b819cea2SGordon Ross fsop_root(vfs_t *vfsp, vnode_t **vpp)
141*b819cea2SGordon Ross {
142*b819cea2SGordon Ross vnode_t *vp;
143*b819cea2SGordon Ross
144*b819cea2SGordon Ross if ((vp = rootdir) == NULL)
145*b819cea2SGordon Ross return (ENXIO);
146*b819cea2SGordon Ross
147*b819cea2SGordon Ross vn_hold(vp);
148*b819cea2SGordon Ross *vpp = vp;
149*b819cea2SGordon Ross return (0);
150*b819cea2SGordon Ross }
151*b819cea2SGordon Ross
152*b819cea2SGordon Ross /* ARGSUSED */
153*b819cea2SGordon Ross int
fsop_statfs(vfs_t * vfsp,statvfs64_t * sp)154*b819cea2SGordon Ross fsop_statfs(vfs_t *vfsp, statvfs64_t *sp)
155*b819cea2SGordon Ross {
156*b819cea2SGordon Ross vnode_t *vp;
157*b819cea2SGordon Ross int rc;
158*b819cea2SGordon Ross
159*b819cea2SGordon Ross if ((vp = rootdir) == NULL)
160*b819cea2SGordon Ross return (ENXIO);
161*b819cea2SGordon Ross
162*b819cea2SGordon Ross rc = fstatvfs64(vp->v_fd, sp);
163*b819cea2SGordon Ross if (rc == -1) {
164*b819cea2SGordon Ross rc = errno;
165*b819cea2SGordon Ross }
166*b819cea2SGordon Ross
167*b819cea2SGordon Ross return (rc);
168*b819cea2SGordon Ross }
169*b819cea2SGordon Ross
170*b819cea2SGordon Ross refstr_t *
vfs_getmntpoint(const struct vfs * vfsp)171*b819cea2SGordon Ross vfs_getmntpoint(const struct vfs *vfsp)
172*b819cea2SGordon Ross {
173*b819cea2SGordon Ross refstr_t *mntpt;
174*b819cea2SGordon Ross
175*b819cea2SGordon Ross mntpt = vfsp->vfs_mntpt;
176*b819cea2SGordon Ross refstr_hold(mntpt);
177*b819cea2SGordon Ross
178*b819cea2SGordon Ross return (mntpt);
179*b819cea2SGordon Ross }
180*b819cea2SGordon Ross
181*b819cea2SGordon Ross /* ARGSUSED */
182*b819cea2SGordon Ross void
vfs_hold(vfs_t * vfsp)183*b819cea2SGordon Ross vfs_hold(vfs_t *vfsp)
184*b819cea2SGordon Ross {
185*b819cea2SGordon Ross }
186*b819cea2SGordon Ross
187*b819cea2SGordon Ross /* ARGSUSED */
188*b819cea2SGordon Ross void
vfs_rele(vfs_t * vfsp)189*b819cea2SGordon Ross vfs_rele(vfs_t *vfsp)
190*b819cea2SGordon Ross {
191*b819cea2SGordon Ross }
192*b819cea2SGordon Ross
193*b819cea2SGordon Ross /* ARGSUSED */
194*b819cea2SGordon Ross int
vfs_lock(vfs_t * vfsp)195*b819cea2SGordon Ross vfs_lock(vfs_t *vfsp)
196*b819cea2SGordon Ross {
197*b819cea2SGordon Ross return (0);
198*b819cea2SGordon Ross }
199*b819cea2SGordon Ross
200*b819cea2SGordon Ross /* ARGSUSED */
201*b819cea2SGordon Ross int
vfs_rlock(vfs_t * vfsp)202*b819cea2SGordon Ross vfs_rlock(vfs_t *vfsp)
203*b819cea2SGordon Ross {
204*b819cea2SGordon Ross return (0);
205*b819cea2SGordon Ross }
206*b819cea2SGordon Ross
207*b819cea2SGordon Ross /* ARGSUSED */
208*b819cea2SGordon Ross void
vfs_lock_wait(vfs_t * vfsp)209*b819cea2SGordon Ross vfs_lock_wait(vfs_t *vfsp)
210*b819cea2SGordon Ross {
211*b819cea2SGordon Ross }
212*b819cea2SGordon Ross
213*b819cea2SGordon Ross /* ARGSUSED */
214*b819cea2SGordon Ross void
vfs_rlock_wait(vfs_t * vfsp)215*b819cea2SGordon Ross vfs_rlock_wait(vfs_t *vfsp)
216*b819cea2SGordon Ross {
217*b819cea2SGordon Ross }
218*b819cea2SGordon Ross
219*b819cea2SGordon Ross /* ARGSUSED */
220*b819cea2SGordon Ross void
vfs_unlock(vfs_t * vfsp)221*b819cea2SGordon Ross vfs_unlock(vfs_t *vfsp)
222*b819cea2SGordon Ross {
223*b819cea2SGordon Ross }
224*b819cea2SGordon Ross
225*b819cea2SGordon Ross
226*b819cea2SGordon Ross static u_longlong_t fs_caller_id;
227*b819cea2SGordon Ross u_longlong_t
fs_new_caller_id(void)228*b819cea2SGordon Ross fs_new_caller_id(void)
229*b819cea2SGordon Ross {
230*b819cea2SGordon Ross return (++fs_caller_id);
231*b819cea2SGordon Ross }
232*b819cea2SGordon Ross
233*b819cea2SGordon Ross static sysid_t lm_sysid;
234*b819cea2SGordon Ross sysid_t
lm_alloc_sysidt(void)235*b819cea2SGordon Ross lm_alloc_sysidt(void)
236*b819cea2SGordon Ross {
237*b819cea2SGordon Ross return (++lm_sysid);
238*b819cea2SGordon Ross }
239*b819cea2SGordon Ross
240*b819cea2SGordon Ross /* ARGSUSED */
241*b819cea2SGordon Ross void
lm_free_sysidt(sysid_t id)242*b819cea2SGordon Ross lm_free_sysidt(sysid_t id)
243*b819cea2SGordon Ross {
244*b819cea2SGordon Ross }
245