1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* vnode ops for the /dev/zvol directory */
#include <sys/types.h>
#include <sys/param.h>
#include <sys/sysmacros.h>
#include <sys/ddi.h>
#include <sys/sunndi.h>
#include <sys/sunldi.h>
#include <fs/fs_subr.h>
#include <sys/fs/dv_node.h>
#include <sys/fs/sdev_impl.h>
#include <sys/zfs_ioctl.h>
#include <sys/policy.h>
#include <sys/stat.h>
#include <sys/vfs_opreg.h>
struct vnodeops *devzvol_vnodeops;
static uint64_t devzvol_gen = 0;
static uint64_t devzvol_zclist;
static size_t devzvol_zclist_size;
static ldi_ident_t devzvol_li;
static ldi_handle_t devzvol_lh;
static kmutex_t devzvol_mtx;
static boolean_t devzvol_isopen;
/*
* we need to use ddi_mod* since fs/dev gets loaded early on in
* startup(), and linking fs/dev to fs/zfs would drag in a lot of
* other stuff (like drv/random) before the rest of the system is
* ready to go
*/
ddi_modhandle_t zfs_mod;
int (*szcm)(char *);
int (*szn2m)(char *, minor_t *);
int
sdev_zvol_create_minor(char *dsname)
{
return ((*szcm)(dsname));
}
int
sdev_zvol_name2minor(char *dsname, minor_t *minor)
{
return ((*szn2m)(dsname, minor));
}
int
devzvol_open_zfs()
{
int rc;
devzvol_li = ldi_ident_from_anon();
if (ldi_open_by_name("/dev/zfs", FREAD | FWRITE, kcred,
&devzvol_lh, devzvol_li))
return (-1);
if (zfs_mod == NULL && ((zfs_mod = ddi_modopen("fs/zfs",
KRTLD_MODE_FIRST, &rc)) == NULL)) {
return (rc);
}
ASSERT(szcm == NULL && szn2m == NULL);
if ((szcm = (int (*)(char *))
ddi_modsym(zfs_mod, "zvol_create_minor", &rc)) == NULL) {
cmn_err(CE_WARN, "couldn't resolve zvol_create_minor");
return (rc);
}
if ((szn2m = (int(*)(char *, minor_t *))
ddi_modsym(zfs_mod, "zvol_name2minor", &rc)) == NULL) {
cmn_err(CE_WARN, "couldn't resolve zvol_name2minor");
return (rc);
}
return (0);
}
void
devzvol_close_zfs()
{
szcm = NULL;
szn2m = NULL;
(void) ldi_close(devzvol_lh, FREAD|FWRITE, kcred);
ldi_ident_release(devzvol_li);
if (zfs_mod != NULL) {
(void) ddi_modclose(zfs_mod);
zfs_mod = NULL;
}
}
int
devzvol_handle_ioctl(int cmd, zfs_cmd_t *zc, size_t *alloc_size)
{
uint64_t cookie;
int size = 8000;
int unused;
int rc;
if (cmd != ZFS_IOC_POOL_CONFIGS)
mutex_enter(&devzvol_mtx);
if (!devzvol_isopen) {
if ((rc = devzvol_open_zfs()) == 0) {
devzvol_isopen = B_TRUE;
} else {
if (cmd != ZFS_IOC_POOL_CONFIGS)
mutex_exit(&devzvol_mtx);
return (ENXIO);
}
}
cookie = zc->zc_cookie;
again:
zc->zc_nvlist_dst = (uint64_t)(intptr_t)kmem_alloc(size,
KM_SLEEP);
zc->zc_nvlist_dst_size = size;
rc = ldi_ioctl(devzvol_lh, cmd, (intptr_t)zc, FKIOCTL, kcred,
&unused);
if (rc == ENOMEM) {
int newsize;
newsize = zc->zc_nvlist_dst_size;
ASSERT(newsize > size);
kmem_free((void *)(uintptr_t)zc->zc_nvlist_dst, size);
size = newsize;
zc->zc_cookie = cookie;
goto again;
}
if (alloc_size == NULL)
kmem_free((void *)(uintptr_t)zc->zc_nvlist_dst, size);
else
*alloc_size = size;
if (cmd != ZFS_IOC_POOL_CONFIGS)
mutex_exit(&devzvol_mtx);
return (rc);
}
/* figures out if the objset exists and returns its type */
int
devzvol_objset_check(char *dsname, dmu_objset_type_t *type)
{
boolean_t ispool;
zfs_cmd_t *zc;
int rc;
zc = kmem_zalloc(sizeof (zfs_cmd_t), KM_SLEEP);
(void) strlcpy(zc->zc_name, dsname, MAXPATHLEN);
ispool = (strchr(dsname, '/') == NULL) ? B_TRUE : B_FALSE;
if (!ispool && sdev_zvol_name2minor(dsname, NULL) == 0) {
sdcmn_err13(("found cached minor node"));
if (type)
*type = DMU_OST_ZVOL;
kmem_free(zc, sizeof (zfs_cmd_t));
return (0);
}
rc = devzvol_handle_ioctl(ispool ? ZFS_IOC_POOL_STATS :
ZFS_IOC_OBJSET_STATS, zc, NULL);
if (type && rc == 0)
*type = (ispool) ? DMU_OST_ZFS :
zc->zc_objset_stats.dds_type;
kmem_free(zc, sizeof (zfs_cmd_t));
return (rc);
}
/*
* returns what the zfs dataset name should be, given the /dev/zvol
* path and an optional name; otherwise NULL
*/
char *
devzvol_make_dsname(const char *path, const char *name)
{
char *dsname;
const char *ptr;
int dslen;
if (strcmp(path, ZVOL_DIR) == 0)
return (NULL);
if (name && (strcmp(name, ".") == 0 || strcmp(name, "..") == 0))
return (NULL);
ptr = path + strlen(ZVOL_DIR);
if (strncmp(ptr, "/dsk", 4) == 0)
ptr += strlen("/dsk");
else if (strncmp(ptr, "/rdsk", 5) == 0)
ptr += strlen("/rdsk");
else
return (NULL);
if (*ptr == '/')
ptr++;
dslen = strlen(ptr);
if (dslen)
dslen++; /* plus null */
if (name)
dslen += strlen(name) + 1; /* plus slash */
dsname = kmem_zalloc(dslen, KM_SLEEP);
if (*ptr) {
(void) strlcpy(dsname, ptr, dslen);
if (name)
(void) strlcat(dsname, "/", dslen);
}
if (name)
(void) strlcat(dsname, name, dslen);
return (dsname);
}
/*
* check if the zvol's sdev_node is still valid, which means make
* sure the zvol is still valid. zvol minors aren't proactively
* destroyed when the zvol is destroyed, so we use a validator to clean
* these up (in other words, when such nodes are encountered during
* subsequent lookup() and readdir() operations) so that only valid
* nodes are returned. The ordering between devname_lookup_func and
* devzvol_validate is a little inefficient in the case of invalid
* or stale nodes because devname_lookup_func calls
* devzvol_create_{dir, link}, then the validator says it's invalid,
* and then the node gets cleaned up.
*/
int
devzvol_validate(struct sdev_node *dv)
{
dmu_objset_type_t do_type;
char *dsname;
char *nm = dv->sdev_name;
int rc;
sdcmn_err13(("validating ('%s' '%s')", dv->sdev_path, nm));
/*
* validate only READY nodes; if someone is sitting on the
* directory of a dataset that just got destroyed we could
* get a zombie node which we just skip.
*/
if (dv->sdev_state != SDEV_READY) {
sdcmn_err13(("skipping '%s'", nm));
return (SDEV_VTOR_SKIP);
}
if ((strcmp(dv->sdev_path, ZVOL_DIR "/dsk") == 0) ||
(strcmp(dv->sdev_path, ZVOL_DIR "/rdsk") == 0))
return (SDEV_VTOR_VALID);
dsname = devzvol_make_dsname(dv->sdev_path, NULL);
if (dsname == NULL)
return (SDEV_VTOR_INVALID);
rc = devzvol_objset_check(dsname, &do_type);
sdcmn_err13((" '%s' rc %d", dsname, rc));
if (rc != 0) {
kmem_free(dsname, strlen(dsname) + 1);
return (SDEV_VTOR_INVALID);
}
sdcmn_err13((" v_type %d do_type %d",
SDEVTOV(dv)->v_type, do_type));
if ((SDEVTOV(dv)->v_type == VLNK && do_type != DMU_OST_ZVOL) ||
(SDEVTOV(dv)->v_type == VDIR && do_type == DMU_OST_ZVOL)) {
kmem_free(dsname, strlen(dsname) + 1);
return (SDEV_VTOR_STALE);
}
if (SDEVTOV(dv)->v_type == VLNK) {
char *ptr, *link;
long val = 0;
minor_t lminor, ominor;
rc = sdev_getlink(SDEVTOV(dv), &link);
ASSERT(rc == 0);
ptr = strrchr(link, ':') + 1;
rc = ddi_strtol(ptr, NULL, 10, &val);
kmem_free(link, strlen(link) + 1);
ASSERT(rc == 0 && val != 0);
lminor = (minor_t)val;
if (sdev_zvol_name2minor(dsname, &ominor) < 0 ||
ominor != lminor) {
kmem_free(dsname, strlen(dsname) + 1);
return (SDEV_VTOR_STALE);
}
}
kmem_free(dsname, strlen(dsname) + 1);
return (SDEV_VTOR_VALID);
}
/*
* creates directories as needed in response to a readdir
*/
void
devzvol_create_pool_dirs(struct vnode *dvp)
{
zfs_cmd_t *zc;
nvlist_t *nv = NULL;
nvpair_t *elem = NULL;
size_t size;
int pools = 0;
int rc;
sdcmn_err13(("devzvol_create_pool_dirs"));
zc = kmem_zalloc(sizeof (zfs_cmd_t), KM_SLEEP);
mutex_enter(&devzvol_mtx);
zc->zc_cookie = devzvol_gen;
rc = devzvol_handle_ioctl(ZFS_IOC_POOL_CONFIGS, zc, &size);
switch (rc) {
case 0:
/* new generation */
ASSERT(devzvol_gen != zc->zc_cookie);
devzvol_gen = zc->zc_cookie;
if (devzvol_zclist)
kmem_free((void *)(uintptr_t)devzvol_zclist,
devzvol_zclist_size);
devzvol_zclist = zc->zc_nvlist_dst;
devzvol_zclist_size = size;
break;
case EEXIST:
/*
* no change in the configuration; still need
* to do lookups in case we did a lookup in
* zvol/rdsk but not zvol/dsk (or vice versa)
*/
kmem_free((void *)(uintptr_t)zc->zc_nvlist_dst,
size);
break;
default:
kmem_free((void *)(uintptr_t)zc->zc_nvlist_dst,
size);
goto out;
}
rc = nvlist_unpack((char *)(uintptr_t)devzvol_zclist,
devzvol_zclist_size, &nv, 0);
if (rc) {
ASSERT(rc == 0);
kmem_free((void *)(uintptr_t)devzvol_zclist,
devzvol_zclist_size);
devzvol_gen = 0;
devzvol_zclist = NULL;
devzvol_zclist_size = 0;
goto out;
}
mutex_exit(&devzvol_mtx);
while ((elem = nvlist_next_nvpair(nv, elem)) != NULL) {
struct vnode *vp;
ASSERT(dvp->v_count > 0);
rc = VOP_LOOKUP(dvp, nvpair_name(elem), &vp, NULL, 0,
NULL, kcred, NULL, 0, NULL);
/* should either work, or not be visible from a zone */
ASSERT(rc == 0 || rc == ENOENT);
if (rc == 0)
VN_RELE(vp);
pools++;
}
nvlist_free(nv);
mutex_enter(&devzvol_mtx);
if (devzvol_isopen && pools == 0) {
/* clean up so zfs can be unloaded */
devzvol_close_zfs();
devzvol_isopen = B_FALSE;
}
out:
mutex_exit(&devzvol_mtx);
kmem_free(zc, sizeof (zfs_cmd_t));
}
/*ARGSUSED3*/
static int
devzvol_create_dir(struct sdev_node *ddv, char *nm, void **arg,
cred_t *cred, void *whatever, char *whichever)
{
timestruc_t now;
struct vattr *vap = (struct vattr *)arg;
sdcmn_err13(("create_dir (%s) (%s) '%s'", ddv->sdev_name,
ddv->sdev_path, nm));
ASSERT(strncmp(ddv->sdev_path, ZVOL_DIR,
strlen(ZVOL_DIR)) == 0);
*vap = *sdev_getdefault_attr(VDIR);
gethrestime(&now);
vap->va_atime = now;
vap->va_mtime = now;
vap->va_ctime = now;
return (0);
}
/*ARGSUSED3*/
static int
devzvol_create_link(struct sdev_node *ddv, char *nm,
void **arg, cred_t *cred, void *whatever, char *whichever)
{
minor_t minor;
char *pathname = (char *)*arg;
int rc;
char *dsname;
char *x;
char str[MAXNAMELEN];
sdcmn_err13(("create_link (%s) (%s) '%s'", ddv->sdev_name,
ddv->sdev_path, nm));
dsname = devzvol_make_dsname(ddv->sdev_path, nm);
rc = sdev_zvol_create_minor(dsname);
if ((rc != 0 && rc != EEXIST && rc != EBUSY) ||
sdev_zvol_name2minor(dsname, &minor)) {
sdcmn_err13(("devzvol_create_link %d", rc));
kmem_free(dsname, strlen(dsname) + 1);
return (-1);
}
kmem_free(dsname, strlen(dsname) + 1);
/*
* This is a valid zvol; create a symlink that points to the
* minor which was created under /devices/pseudo/zfs@0
*/
*pathname = '\0';
for (x = ddv->sdev_path; x = strchr(x, '/'); x++)
(void) strcat(pathname, "../");
(void) snprintf(str, sizeof (str), ZVOL_PSEUDO_DEV "%u", minor);
(void) strncat(pathname, str, MAXPATHLEN);
if (strncmp(ddv->sdev_path, ZVOL_FULL_RDEV_DIR,
strlen(ZVOL_FULL_RDEV_DIR)) == 0)
(void) strcat(pathname, ",raw");
return (0);
}
/* Clean zvol sdev_nodes that are no longer valid. */
static void
devzvol_prunedir(struct sdev_node *ddv)
{
struct sdev_node *dv;
ASSERT(RW_READ_HELD(&ddv->sdev_contents));
sdcmn_err13(("prunedir '%s'", ddv->sdev_name));
ASSERT(strncmp(ddv->sdev_path, ZVOL_DIR, strlen(ZVOL_DIR)) == 0);
if (rw_tryupgrade(&ddv->sdev_contents) == 0) {
rw_exit(&ddv->sdev_contents);
rw_enter(&ddv->sdev_contents, RW_WRITER);
}
dv = SDEV_FIRST_ENTRY(ddv);
while (dv) {
sdcmn_err13(("sdev_name '%s'", dv->sdev_name));
/* skip stale nodes */
if (dv->sdev_flags & SDEV_STALE) {
sdcmn_err13((" stale"));
dv = SDEV_NEXT_ENTRY(ddv, dv);
continue;
}
switch (devzvol_validate(dv)) {
case SDEV_VTOR_VALID:
case SDEV_VTOR_SKIP:
dv = SDEV_NEXT_ENTRY(ddv, dv);
continue;
case SDEV_VTOR_INVALID:
sdcmn_err7(("prunedir: destroy invalid "
"node: %s\n", dv->sdev_name));
break;
}
if ((SDEVTOV(dv)->v_type == VDIR) &&
(sdev_cleandir(dv, NULL, 0) != 0)) {
dv = SDEV_NEXT_ENTRY(ddv, dv);
continue;
}
SDEV_HOLD(dv);
/* remove the cache node */
if (sdev_cache_update(ddv, &dv, dv->sdev_name,
SDEV_CACHE_DELETE) == 0)
dv = SDEV_FIRST_ENTRY(ddv);
else
dv = SDEV_NEXT_ENTRY(ddv, dv);
}
rw_downgrade(&ddv->sdev_contents);
}
/*ARGSUSED*/
static int
devzvol_lookup(struct vnode *dvp, char *nm, struct vnode **vpp,
struct pathname *pnp, int flags, struct vnode *rdir, struct cred *cred,
caller_context_t *ct, int *direntflags, pathname_t *realpnp)
{
enum vtype expected_type = VDIR;
struct sdev_node *parent = VTOSDEV(dvp);
char *dsname;
dmu_objset_type_t do_type;
int error;
sdcmn_err13(("devzvol_lookup '%s' '%s'", parent->sdev_path, nm));
*vpp = NULL;
/* execute access is required to search the directory */
if ((error = VOP_ACCESS(dvp, VEXEC, 0, cred, ct)) != 0)
return (error);
rw_enter(&parent->sdev_contents, RW_READER);
if (!SDEV_IS_GLOBAL(parent)) {
rw_exit(&parent->sdev_contents);
return (prof_lookup(dvp, nm, vpp, cred));
}
dsname = devzvol_make_dsname(parent->sdev_path, nm);
rw_exit(&parent->sdev_contents);
sdcmn_err13(("rvp dsname %s", dsname ? dsname : "(null)"));
if (dsname) {
error = devzvol_objset_check(dsname, &do_type);
if (error != 0) {
error = ENOENT;
goto out;
}
if (do_type == DMU_OST_ZVOL)
expected_type = VLNK;
}
/*
* the callbacks expect:
*
* parent->sdev_path nm
* /dev/zvol {r}dsk
* /dev/zvol/{r}dsk <pool name>
* /dev/zvol/{r}dsk/<dataset name> <last ds component>
*
* sdev_name is always last path component of sdev_path
*/
if (expected_type == VDIR) {
error = devname_lookup_func(parent, nm, vpp, cred,
devzvol_create_dir, SDEV_VATTR);
} else {
error = devname_lookup_func(parent, nm, vpp, cred,
devzvol_create_link, SDEV_VLINK);
}
sdcmn_err13(("devzvol_lookup %d %d", expected_type, error));
ASSERT(error || ((*vpp)->v_type == expected_type));
out:
if (dsname)
kmem_free(dsname, strlen(dsname) + 1);
sdcmn_err13(("devzvol_lookup %d", error));
return (error);
}
/*
* We allow create to find existing nodes
* - if the node doesn't exist - EROFS
* - creating an existing dir read-only succeeds, otherwise EISDIR
* - exclusive creates fail - EEXIST
*/
/*ARGSUSED2*/
static int
devzvol_create(struct vnode *dvp, char *nm, struct vattr *vap, vcexcl_t excl,
int mode, struct vnode **vpp, struct cred *cred, int flag,
caller_context_t *ct, vsecattr_t *vsecp)
{
int error;
struct vnode *vp;
*vpp = NULL;
error = devzvol_lookup(dvp, nm, &vp, NULL, 0, NULL, cred, ct, NULL,
NULL);
if (error == 0) {
if (excl == EXCL)
error = EEXIST;
else if (vp->v_type == VDIR && (mode & VWRITE))
error = EISDIR;
else
error = VOP_ACCESS(vp, mode, 0, cred, ct);
if (error) {
VN_RELE(vp);
} else
*vpp = vp;
} else if (error == ENOENT) {
error = EROFS;
}
return (error);
}
void sdev_iter_snapshots(struct vnode *dvp, char *name);
void
sdev_iter_datasets(struct vnode *dvp, int arg, char *name)
{
zfs_cmd_t *zc;
int rc;
sdcmn_err13(("iter name is '%s' (arg %x)", name, arg));
zc = kmem_zalloc(sizeof (zfs_cmd_t), KM_SLEEP);
(void) strcpy(zc->zc_name, name);
while ((rc = devzvol_handle_ioctl(arg, zc, B_FALSE)) == 0) {
struct vnode *vpp;
char *ptr;
sdcmn_err13((" name %s", zc->zc_name));
if (strchr(zc->zc_name, '$') || strchr(zc->zc_name, '%'))
goto skip;
ptr = strrchr(zc->zc_name, '/') + 1;
rc = devzvol_lookup(dvp, ptr, &vpp, NULL, 0, NULL,
kcred, NULL, NULL, NULL);
if (rc == 0) {
VN_RELE(vpp);
} else if (rc == ENOENT) {
goto skip;
} else {
/* EBUSY == problem with zvols's dmu holds? */
ASSERT(0);
goto skip;
}
if (arg == ZFS_IOC_DATASET_LIST_NEXT &&
zc->zc_objset_stats.dds_type != DMU_OST_ZFS)
sdev_iter_snapshots(dvp, zc->zc_name);
skip:
(void) strcpy(zc->zc_name, name);
}
kmem_free(zc, sizeof (zfs_cmd_t));
}
void
sdev_iter_snapshots(struct vnode *dvp, char *name)
{
sdev_iter_datasets(dvp, ZFS_IOC_SNAPSHOT_LIST_NEXT, name);
}
/*ARGSUSED4*/
static int
devzvol_readdir(struct vnode *dvp, struct uio *uiop, struct cred *cred,
int *eofp, caller_context_t *ct_unused, int flags_unused)
{
struct sdev_node *sdvp = VTOSDEV(dvp);
char *ptr;
sdcmn_err13(("zv readdir of '%s' %s'", sdvp->sdev_path,
sdvp->sdev_name));
if (strcmp(sdvp->sdev_path, ZVOL_DIR) == 0) {
struct vnode *vp;
rw_exit(&sdvp->sdev_contents);
(void) devname_lookup_func(sdvp, "dsk", &vp, cred,
devzvol_create_dir, SDEV_VATTR);
VN_RELE(vp);
(void) devname_lookup_func(sdvp, "rdsk", &vp, cred,
devzvol_create_dir, SDEV_VATTR);
VN_RELE(vp);
rw_enter(&sdvp->sdev_contents, RW_READER);
return (devname_readdir_func(dvp, uiop, cred, eofp, 0));
}
if (uiop->uio_offset == 0)
devzvol_prunedir(sdvp);
ptr = sdvp->sdev_path + strlen(ZVOL_DIR);
if ((strcmp(ptr, "/dsk") == 0) || (strcmp(ptr, "/rdsk") == 0)) {
rw_exit(&sdvp->sdev_contents);
devzvol_create_pool_dirs(dvp);
rw_enter(&sdvp->sdev_contents, RW_READER);
return (devname_readdir_func(dvp, uiop, cred, eofp, 0));
}
ptr = strchr(ptr + 1, '/') + 1;
rw_exit(&sdvp->sdev_contents);
sdev_iter_datasets(dvp, ZFS_IOC_DATASET_LIST_NEXT, ptr);
rw_enter(&sdvp->sdev_contents, RW_READER);
return (devname_readdir_func(dvp, uiop, cred, eofp, 0));
}
const fs_operation_def_t devzvol_vnodeops_tbl[] = {
VOPNAME_READDIR, { .vop_readdir = devzvol_readdir },
VOPNAME_LOOKUP, { .vop_lookup = devzvol_lookup },
VOPNAME_CREATE, { .vop_create = devzvol_create },
VOPNAME_RENAME, { .error = fs_nosys },
VOPNAME_MKDIR, { .error = fs_nosys },
VOPNAME_RMDIR, { .error = fs_nosys },
VOPNAME_REMOVE, { .error = fs_nosys },
VOPNAME_SYMLINK, { .error = fs_nosys },
NULL, NULL
};
|