302 fsop_sync_by_kind(int fstype, short flag, cred_t *cr)
303 {
304 ASSERT((fstype >= 0) && (fstype < nfstype));
305
306 if (ALLOCATED_VFSSW(&vfssw[fstype]) && VFS_INSTALLED(&vfssw[fstype]))
307 return (*vfssw[fstype].vsw_vfsops.vfs_sync) (NULL, flag, cr);
308 else
309 return (ENOTSUP);
310 }
311
312 /*
313 * File system initialization. vfs_setfsops() must be called from a file
314 * system's init routine.
315 */
316
317 static int
318 fs_copyfsops(const fs_operation_def_t *template, vfsops_t *actual,
319 int *unused_ops)
320 {
321 static const fs_operation_trans_def_t vfs_ops_table[] = {
322 VFSNAME_MOUNT, offsetof(vfsops_t, vfs_mount),
323 fs_nosys, fs_nosys,
324
325 VFSNAME_UNMOUNT, offsetof(vfsops_t, vfs_unmount),
326 fs_nosys, fs_nosys,
327
328 VFSNAME_ROOT, offsetof(vfsops_t, vfs_root),
329 fs_nosys, fs_nosys,
330
331 VFSNAME_STATVFS, offsetof(vfsops_t, vfs_statvfs),
332 fs_nosys, fs_nosys,
333
334 VFSNAME_SYNC, offsetof(vfsops_t, vfs_sync),
335 (fs_generic_func_p) fs_sync,
336 (fs_generic_func_p) fs_sync, /* No errors allowed */
337
338 VFSNAME_VGET, offsetof(vfsops_t, vfs_vget),
339 fs_nosys, fs_nosys,
340
341 VFSNAME_MOUNTROOT, offsetof(vfsops_t, vfs_mountroot),
342 fs_nosys, fs_nosys,
343
344 VFSNAME_FREEVFS, offsetof(vfsops_t, vfs_freevfs),
345 (fs_generic_func_p)fs_freevfs,
346 (fs_generic_func_p)fs_freevfs, /* Shouldn't fail */
347
348 VFSNAME_VNSTATE, offsetof(vfsops_t, vfs_vnstate),
349 (fs_generic_func_p)fs_nosys,
350 (fs_generic_func_p)fs_nosys,
351
352 NULL, 0, NULL, NULL
353 };
354
355 return (fs_build_vector(actual, unused_ops, vfs_ops_table, template));
356 }
357
358 void
359 zfs_boot_init(void)
360 {
361 if (strcmp(rootfs.bo_fstype, MNTTYPE_ZFS) == 0)
362 spa_boot_init();
363 }
364
365 int
366 vfs_setfsops(int fstype, const fs_operation_def_t *template, vfsops_t **actual)
367 {
368 int error;
369 int unused_ops;
370
371 /*
372 * Verify that fstype refers to a valid fs. Note that
2813 {
2814 bzero(vap, sizeof (vattr_t));
2815 vap->va_type = VREG;
2816 vap->va_nlink = 1;
2817 vap->va_ctime = vfs_mnttab_ctime;
2818 /*
2819 * it is ok to just copy mtime as the time will be monotonically
2820 * increasing.
2821 */
2822 vap->va_mtime = vfs_mnttab_mtime;
2823 vap->va_atime = vap->va_mtime;
2824 return (0);
2825 }
2826
2827 static void
2828 vfs_mnttabvp_setup(void)
2829 {
2830 vnode_t *tvp;
2831 vnodeops_t *vfs_mntdummyvnops;
2832 const fs_operation_def_t mnt_dummyvnodeops_template[] = {
2833 VOPNAME_READ, { .vop_read = vfs_mntdummyread },
2834 VOPNAME_WRITE, { .vop_write = vfs_mntdummywrite },
2835 VOPNAME_GETATTR, { .vop_getattr = vfs_mntdummygetattr },
2836 VOPNAME_VNEVENT, { .vop_vnevent = fs_vnevent_support },
2837 NULL, NULL
2838 };
2839
2840 if (vn_make_ops("mnttab", mnt_dummyvnodeops_template,
2841 &vfs_mntdummyvnops) != 0) {
2842 cmn_err(CE_WARN, "vfs_mnttabvp_setup: vn_make_ops failed");
2843 /* Shouldn't happen, but not bad enough to panic */
2844 return;
2845 }
2846
2847 /*
2848 * A global dummy vnode is allocated to represent mntfs files.
2849 * The mntfs file (/etc/mnttab) can be monitored for file events
2850 * and receive an event when mnttab changes. Dummy VOP calls
2851 * will be made on this vnode. The file events notification module
2852 * intercepts this vnode and delivers relevant events.
2853 */
2854 tvp = vn_alloc(KM_SLEEP);
2855 tvp->v_flag = VNOMOUNT|VNOMAP|VNOSWAP|VNOCACHE;
2856 vn_setops(tvp, vfs_mntdummyvnops);
2857 tvp->v_type = VREG;
4204 vfs_EIO_sync(struct vfs *vfsp, short arg, struct cred *cr)
4205 {
4206 return (EIO);
4207 }
4208
4209 vfs_t EIO_vfs;
4210 vfsops_t *EIO_vfsops;
4211
4212 /*
4213 * Called from startup() to initialize all loaded vfs's
4214 */
4215 void
4216 vfsinit(void)
4217 {
4218 struct vfssw *vswp;
4219 int error;
4220 extern int vopstats_enabled;
4221 extern void vopstats_startup();
4222
4223 static const fs_operation_def_t EIO_vfsops_template[] = {
4224 VFSNAME_MOUNT, { .error = vfs_EIO },
4225 VFSNAME_UNMOUNT, { .error = vfs_EIO },
4226 VFSNAME_ROOT, { .error = vfs_EIO },
4227 VFSNAME_STATVFS, { .error = vfs_EIO },
4228 VFSNAME_SYNC, { .vfs_sync = vfs_EIO_sync },
4229 VFSNAME_VGET, { .error = vfs_EIO },
4230 VFSNAME_MOUNTROOT, { .error = vfs_EIO },
4231 VFSNAME_FREEVFS, { .error = vfs_EIO },
4232 VFSNAME_VNSTATE, { .error = vfs_EIO },
4233 NULL, NULL
4234 };
4235
4236 static const fs_operation_def_t stray_vfsops_template[] = {
4237 VFSNAME_MOUNT, { .error = vfsstray },
4238 VFSNAME_UNMOUNT, { .error = vfsstray },
4239 VFSNAME_ROOT, { .error = vfsstray },
4240 VFSNAME_STATVFS, { .error = vfsstray },
4241 VFSNAME_SYNC, { .vfs_sync = vfsstray_sync },
4242 VFSNAME_VGET, { .error = vfsstray },
4243 VFSNAME_MOUNTROOT, { .error = vfsstray },
4244 VFSNAME_FREEVFS, { .error = vfsstray },
4245 VFSNAME_VNSTATE, { .error = vfsstray },
4246 NULL, NULL
4247 };
4248
4249 /* Create vfs cache */
4250 vfs_cache = kmem_cache_create("vfs_cache", sizeof (struct vfs),
4251 sizeof (uintptr_t), NULL, NULL, NULL, NULL, NULL, 0);
4252
4253 /* Initialize the vnode cache (file systems may use it during init). */
4254 vn_create_cache();
4255
4256 /* Setup event monitor framework */
4257 fem_init();
4258
4259 /* Initialize the dummy stray file system type. */
4260 error = vfs_setfsops(0, stray_vfsops_template, NULL);
4261
4262 /* Initialize the dummy EIO file system. */
4263 error = vfs_makefsops(EIO_vfsops_template, &EIO_vfsops);
4264 if (error != 0) {
4265 cmn_err(CE_WARN, "vfsinit: bad EIO vfs ops template");
4266 /* Shouldn't happen, but not bad enough to panic */
|
302 fsop_sync_by_kind(int fstype, short flag, cred_t *cr)
303 {
304 ASSERT((fstype >= 0) && (fstype < nfstype));
305
306 if (ALLOCATED_VFSSW(&vfssw[fstype]) && VFS_INSTALLED(&vfssw[fstype]))
307 return (*vfssw[fstype].vsw_vfsops.vfs_sync) (NULL, flag, cr);
308 else
309 return (ENOTSUP);
310 }
311
312 /*
313 * File system initialization. vfs_setfsops() must be called from a file
314 * system's init routine.
315 */
316
317 static int
318 fs_copyfsops(const fs_operation_def_t *template, vfsops_t *actual,
319 int *unused_ops)
320 {
321 static const fs_operation_trans_def_t vfs_ops_table[] = {
322 { VFSNAME_MOUNT, offsetof(vfsops_t, vfs_mount),
323 fs_nosys, fs_nosys },
324
325 { VFSNAME_UNMOUNT, offsetof(vfsops_t, vfs_unmount),
326 fs_nosys, fs_nosys },
327
328 { VFSNAME_ROOT, offsetof(vfsops_t, vfs_root),
329 fs_nosys, fs_nosys },
330
331 { VFSNAME_STATVFS, offsetof(vfsops_t, vfs_statvfs),
332 fs_nosys, fs_nosys },
333
334 { VFSNAME_SYNC, offsetof(vfsops_t, vfs_sync),
335 (fs_generic_func_p) fs_sync,
336 (fs_generic_func_p) fs_sync }, /* No errors allowed */
337
338 { VFSNAME_VGET, offsetof(vfsops_t, vfs_vget),
339 fs_nosys, fs_nosys },
340
341 { VFSNAME_MOUNTROOT, offsetof(vfsops_t, vfs_mountroot),
342 fs_nosys, fs_nosys },
343
344 { VFSNAME_FREEVFS, offsetof(vfsops_t, vfs_freevfs),
345 (fs_generic_func_p)fs_freevfs,
346 (fs_generic_func_p)fs_freevfs }, /* Shouldn't fail */
347
348 { VFSNAME_VNSTATE, offsetof(vfsops_t, vfs_vnstate),
349 (fs_generic_func_p)fs_nosys,
350 (fs_generic_func_p)fs_nosys },
351
352 { NULL, 0, NULL, NULL }
353 };
354
355 return (fs_build_vector(actual, unused_ops, vfs_ops_table, template));
356 }
357
358 void
359 zfs_boot_init(void)
360 {
361 if (strcmp(rootfs.bo_fstype, MNTTYPE_ZFS) == 0)
362 spa_boot_init();
363 }
364
365 int
366 vfs_setfsops(int fstype, const fs_operation_def_t *template, vfsops_t **actual)
367 {
368 int error;
369 int unused_ops;
370
371 /*
372 * Verify that fstype refers to a valid fs. Note that
2813 {
2814 bzero(vap, sizeof (vattr_t));
2815 vap->va_type = VREG;
2816 vap->va_nlink = 1;
2817 vap->va_ctime = vfs_mnttab_ctime;
2818 /*
2819 * it is ok to just copy mtime as the time will be monotonically
2820 * increasing.
2821 */
2822 vap->va_mtime = vfs_mnttab_mtime;
2823 vap->va_atime = vap->va_mtime;
2824 return (0);
2825 }
2826
2827 static void
2828 vfs_mnttabvp_setup(void)
2829 {
2830 vnode_t *tvp;
2831 vnodeops_t *vfs_mntdummyvnops;
2832 const fs_operation_def_t mnt_dummyvnodeops_template[] = {
2833 { VOPNAME_READ, { .vop_read = vfs_mntdummyread } },
2834 { VOPNAME_WRITE, { .vop_write = vfs_mntdummywrite } },
2835 { VOPNAME_GETATTR, { .vop_getattr = vfs_mntdummygetattr }},
2836 { VOPNAME_VNEVENT, { .vop_vnevent = fs_vnevent_support } },
2837 { NULL, { NULL } }
2838 };
2839
2840 if (vn_make_ops("mnttab", mnt_dummyvnodeops_template,
2841 &vfs_mntdummyvnops) != 0) {
2842 cmn_err(CE_WARN, "vfs_mnttabvp_setup: vn_make_ops failed");
2843 /* Shouldn't happen, but not bad enough to panic */
2844 return;
2845 }
2846
2847 /*
2848 * A global dummy vnode is allocated to represent mntfs files.
2849 * The mntfs file (/etc/mnttab) can be monitored for file events
2850 * and receive an event when mnttab changes. Dummy VOP calls
2851 * will be made on this vnode. The file events notification module
2852 * intercepts this vnode and delivers relevant events.
2853 */
2854 tvp = vn_alloc(KM_SLEEP);
2855 tvp->v_flag = VNOMOUNT|VNOMAP|VNOSWAP|VNOCACHE;
2856 vn_setops(tvp, vfs_mntdummyvnops);
2857 tvp->v_type = VREG;
4204 vfs_EIO_sync(struct vfs *vfsp, short arg, struct cred *cr)
4205 {
4206 return (EIO);
4207 }
4208
4209 vfs_t EIO_vfs;
4210 vfsops_t *EIO_vfsops;
4211
4212 /*
4213 * Called from startup() to initialize all loaded vfs's
4214 */
4215 void
4216 vfsinit(void)
4217 {
4218 struct vfssw *vswp;
4219 int error;
4220 extern int vopstats_enabled;
4221 extern void vopstats_startup();
4222
4223 static const fs_operation_def_t EIO_vfsops_template[] = {
4224 { VFSNAME_MOUNT, { .error = vfs_EIO } },
4225 { VFSNAME_UNMOUNT, { .error = vfs_EIO } },
4226 { VFSNAME_ROOT, { .error = vfs_EIO } },
4227 { VFSNAME_STATVFS, { .error = vfs_EIO } },
4228 { VFSNAME_SYNC, { .vfs_sync = vfs_EIO_sync } },
4229 { VFSNAME_VGET, { .error = vfs_EIO } },
4230 { VFSNAME_MOUNTROOT, { .error = vfs_EIO } },
4231 { VFSNAME_FREEVFS, { .error = vfs_EIO } },
4232 { VFSNAME_VNSTATE, { .error = vfs_EIO } },
4233 { NULL, { NULL } }
4234 };
4235
4236 static const fs_operation_def_t stray_vfsops_template[] = {
4237 { VFSNAME_MOUNT, { .error = vfsstray } },
4238 { VFSNAME_UNMOUNT, { .error = vfsstray } },
4239 { VFSNAME_ROOT, { .error = vfsstray } },
4240 { VFSNAME_STATVFS, { .error = vfsstray } },
4241 { VFSNAME_SYNC, { .vfs_sync = vfsstray_sync } },
4242 { VFSNAME_VGET, { .error = vfsstray } },
4243 { VFSNAME_MOUNTROOT, { .error = vfsstray } },
4244 { VFSNAME_FREEVFS, { .error = vfsstray } },
4245 { VFSNAME_VNSTATE, { .error = vfsstray } },
4246 { NULL, { NULL } }
4247 };
4248
4249 /* Create vfs cache */
4250 vfs_cache = kmem_cache_create("vfs_cache", sizeof (struct vfs),
4251 sizeof (uintptr_t), NULL, NULL, NULL, NULL, NULL, 0);
4252
4253 /* Initialize the vnode cache (file systems may use it during init). */
4254 vn_create_cache();
4255
4256 /* Setup event monitor framework */
4257 fem_init();
4258
4259 /* Initialize the dummy stray file system type. */
4260 error = vfs_setfsops(0, stray_vfsops_template, NULL);
4261
4262 /* Initialize the dummy EIO file system. */
4263 error = vfs_makefsops(EIO_vfsops_template, &EIO_vfsops);
4264 if (error != 0) {
4265 cmn_err(CE_WARN, "vfsinit: bad EIO vfs ops template");
4266 /* Shouldn't happen, but not bad enough to panic */
|