summaryrefslogtreecommitdiff
path: root/usr/src/uts/common/io/vscan/vscan_drv.c
blob: 6247eea5f7bb0851f8de9938438ae4df2850cb0a (plain)
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
687
688
689
690
691
/*
 * 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.
 */

#include <sys/stat.h>
#include <sys/ddi.h>
#include <sys/sunddi.h>
#include <sys/time.h>
#include <sys/varargs.h>
#include <sys/conf.h>
#include <sys/modctl.h>
#include <sys/vnode.h>
#include <fs/fs_subr.h>
#include <sys/types.h>
#include <sys/file.h>
#include <sys/disp.h>
#include <sys/vscan.h>
#include <sys/policy.h>
#include <sys/sdt.h>


/* seconds to wait for daemon to reconnect before disabling */
#define	VS_DAEMON_WAIT_SEC	60

/* length of minor node name - vscan%d */
#define	VS_NODENAME_LEN		16

/* global variables - tunable via /etc/system */
uint32_t vs_reconnect_timeout = VS_DAEMON_WAIT_SEC;
extern uint32_t vs_nodes_max;	/* max in-progress scan requests */

/*
 * vscan_drv_state
 *
 * Operations on instance 0 represent vscand initiated state
 * transition events:
 * open(0) - vscand connect
 * close(0) - vscan disconnect
 * enable(0) - vscand enable (ready to hand requests)
 * disable(0) - vscand disable (shutting down)
 *
 *   +------------------------+
 *   | VS_DRV_UNCONFIG        |
 *   +------------------------+
 *      |           ^
 *      | attach    | detach
 *      v           |
 *   +------------------------+
 *   | VS_DRV_IDLE            |<------|
 *   +------------------------+       |
 *      |           ^                 |
 *      | open(0)   | close(0)        |
 *      v           |                 |
 *   +------------------------+       |
 *   | VS_DRV_CONNECTED       |<-|    |
 *   +------------------------+  |    |
 *      |           ^            |    |
 *      | enable(0) | disable(0) |    |
 *      v           |            |    |
 *   +------------------------+  |    |
 *   | VS_DRV_ENABLED         |  |    |
 *   +------------------------+  |    |
 *      |                        |    |
 *      | close(0)            open(0) |
 *      v                        |    |
 *   +------------------------+  |    | timeout
 *   | VS_DRV_DELAYED_DISABLE | --    |
 *   +------------------------+	------|
 *
 */
typedef enum {
	VS_DRV_UNCONFIG,
	VS_DRV_IDLE,
	VS_DRV_CONNECTED,
	VS_DRV_ENABLED,
	VS_DRV_DELAYED_DISABLE
} vscan_drv_state_t;
static vscan_drv_state_t vscan_drv_state = VS_DRV_UNCONFIG;


/*
 * vscan_drv_inst_state
 *
 * Instance 0 controls the state of the driver: vscan_drv_state.
 * vscan_drv_inst_state[0] should NOT be used.
 *
 * vscan_drv_inst_state[n] represents the state of driver
 * instance n, used by vscand to access file data for the
 * scan request with index n in vscan_svc_reqs.
 * Minor nodes are created as required then all are destroyed
 * during driver detach.
 *
 *   +------------------------+
 *   | VS_DRV_INST_UNCONFIG   |
 *   +------------------------+
 *      |                 ^
 *      | create_node(n)  | detach
 *      v                 |
 *   +------------------------+
 *   | VS_DRV_INST_INIT       |<-|
 *   +------------------------+  |
 *      |                        |
 *      | open(n)                |
 *      v                        |
 *   +------------------------+  |
 *   | VS_DRV_INST_OPEN       |--|
 *   +------------------------+  |
 *      |                        |
 *      | read(n)                |
 *      v                        | close(n)
 *   +------------------------+  |
 *   | VS_DRV_INST_READING    |--|
 *   +------------------------+
 */
typedef enum {
	VS_DRV_INST_UNCONFIG = 0, /* minor node not created */
	VS_DRV_INST_INIT,
	VS_DRV_INST_OPEN,
	VS_DRV_INST_READING
} vscan_drv_inst_state_t;

static vscan_drv_inst_state_t *vscan_drv_inst_state;
static int vscan_drv_inst_state_sz;

static dev_info_t *vscan_drv_dip;
static kmutex_t vscan_drv_mutex;
static kcondvar_t vscan_drv_cv; /* wait for daemon reconnect */

/*
 * DDI entry points.
 */
static int vscan_drv_attach(dev_info_t *, ddi_attach_cmd_t);
static int vscan_drv_detach(dev_info_t *, ddi_detach_cmd_t);
static int vscan_drv_getinfo(dev_info_t *, ddi_info_cmd_t, void *, void **);
static int vscan_drv_open(dev_t *, int, int, cred_t *);
static int vscan_drv_close(dev_t, int, int, cred_t *);
static int vscan_drv_read(dev_t, struct uio *, cred_t *);
static int vscan_drv_ioctl(dev_t, int, intptr_t, int, cred_t *, int *);

static boolean_t vscan_drv_in_use(void);
static void vscan_drv_delayed_disable(void);


/*
 * module linkage info for the kernel
 */
static struct cb_ops cbops = {
	vscan_drv_open,		/* cb_open */
	vscan_drv_close,	/* cb_close */
	nodev,			/* cb_strategy */
	nodev,			/* cb_print */
	nodev,			/* cb_dump */
	vscan_drv_read,		/* cb_read */
	nodev,			/* cb_write */
	vscan_drv_ioctl,	/* cb_ioctl */
	nodev,			/* cb_devmap */
	nodev,			/* cb_mmap */
	nodev,			/* cb_segmap */
	nochpoll,		/* cb_chpoll */
	ddi_prop_op,		/* cb_prop_op */
	NULL,			/* cb_streamtab */
	D_MP,			/* cb_flag */
	CB_REV,			/* cb_rev */
	nodev,			/* cb_aread */
	nodev,			/* cb_awrite */
};

static struct dev_ops devops = {
	DEVO_REV,		/* devo_rev */
	0,			/* devo_refcnt */
	vscan_drv_getinfo,	/* devo_getinfo */
	nulldev,		/* devo_identify */
	nulldev,		/* devo_probe */
	vscan_drv_attach,	/* devo_attach */
	vscan_drv_detach,	/* devo_detach */
	nodev,			/* devo_reset */
	&cbops,			/* devo_cb_ops */
	NULL,			/* devo_bus_ops */
	NULL,			/* devo_power */
	ddi_quiesce_not_needed,		/* devo_quiesce */
};

static struct modldrv modldrv = {
	&mod_driverops,		/* drv_modops */
	"virus scanning",	/* drv_linkinfo */
	&devops,
};

static struct modlinkage modlinkage = {

	MODREV_1,	/* revision of the module, must be: MODREV_1	*/
	&modldrv,	/* ptr to linkage structures			*/
	NULL,
};


/*
 * _init
 */
int
_init(void)
{
	int rc;

	vscan_drv_inst_state_sz =
	    sizeof (vscan_drv_inst_state_t) * (vs_nodes_max + 1);

	if (vscan_door_init() != 0)
		return (DDI_FAILURE);

	if (vscan_svc_init() != 0) {
		vscan_door_fini();
		return (DDI_FAILURE);
	}

	mutex_init(&vscan_drv_mutex, NULL, MUTEX_DRIVER, NULL);
	vscan_drv_inst_state = kmem_zalloc(vscan_drv_inst_state_sz, KM_SLEEP);

	cv_init(&vscan_drv_cv, NULL, CV_DEFAULT, NULL);

	if ((rc  = mod_install(&modlinkage)) != 0) {
		vscan_door_fini();
		vscan_svc_fini();
		kmem_free(vscan_drv_inst_state, vscan_drv_inst_state_sz);
		cv_destroy(&vscan_drv_cv);
		mutex_destroy(&vscan_drv_mutex);
	}

	return (rc);
}


/*
 * _info
 */
int
_info(struct modinfo *modinfop)
{
	return (mod_info(&modlinkage, modinfop));
}


/*
 * _fini
 */
int
_fini(void)
{
	int rc;

	if (vscan_drv_in_use())
		return (EBUSY);

	if ((rc = mod_remove(&modlinkage)) == 0) {
		vscan_door_fini();
		vscan_svc_fini();
		kmem_free(vscan_drv_inst_state, vscan_drv_inst_state_sz);
		cv_destroy(&vscan_drv_cv);
		mutex_destroy(&vscan_drv_mutex);
	}

	return (rc);
}


/*
 * DDI entry points.
 */

/*
 * vscan_drv_getinfo
 */
/* ARGSUSED */
static int
vscan_drv_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result)
{
	ulong_t inst = getminor((dev_t)arg);

	switch (cmd) {
	case DDI_INFO_DEVT2DEVINFO:
		*result = vscan_drv_dip;
		return (DDI_SUCCESS);
	case DDI_INFO_DEVT2INSTANCE:
		*result = (void *)inst;
		return (DDI_SUCCESS);
	}
	return (DDI_FAILURE);
}


/*
 * vscan_drv_attach
 */
static int
vscan_drv_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
{
	if (cmd != DDI_ATTACH)
		return (DDI_FAILURE);

	if (ddi_get_instance(dip) != 0)
		return (DDI_FAILURE);

	vscan_drv_dip = dip;

	/* create minor node 0 for daemon-driver synchronization */
	if (vscan_drv_create_node(0) == B_FALSE)
		return (DDI_FAILURE);

	vscan_drv_state = VS_DRV_IDLE;
	return (DDI_SUCCESS);
}


/*
 * vscan_drv_detach
 */
static int
vscan_drv_detach(dev_info_t *dip, ddi_detach_cmd_t cmd)
{
	int i;

	if (cmd != DDI_DETACH)
		return (DDI_FAILURE);

	if (ddi_get_instance(dip) != 0)
		return (DDI_FAILURE);

	if (vscan_drv_in_use())
		return (DDI_FAILURE);

	/* remove all minor nodes */
	vscan_drv_dip = NULL;
	ddi_remove_minor_node(dip, NULL);
	for (i = 0; i <= vs_nodes_max; i++)
		vscan_drv_inst_state[i] = VS_DRV_INST_UNCONFIG;

	vscan_drv_state = VS_DRV_UNCONFIG;
	return (DDI_SUCCESS);
}


/*
 * vscan_drv_in_use
 *
 * If the driver state is not IDLE or UNCONFIG then the
 * driver is in use. Otherwise, check the service interface
 * (vscan_svc) to see if it is still in use - for example
 * there there may be requests still in progress.
 */
static boolean_t
vscan_drv_in_use()
{
	boolean_t in_use = B_FALSE;

	mutex_enter(&vscan_drv_mutex);
	if ((vscan_drv_state != VS_DRV_IDLE) &&
	    (vscan_drv_state != VS_DRV_UNCONFIG)) {
		in_use = B_TRUE;
	}
	mutex_exit(&vscan_drv_mutex);

	if (in_use)
		return (B_TRUE);
	else
		return (vscan_svc_in_use());
}


/*
 * vscan_drv_open
 *
 * If inst == 0, this is vscand initializing.
 * If the driver is in DELAYED_DISABLE, ie vscand previously
 * disconnected without a clean shutdown and the driver is
 * waiting for a period to allow vscand to reconnect, signal
 * vscan_drv_cv to cancel the delayed disable.
 *
 * If inst != 0, open the file associated with inst.
 */
/* ARGSUSED */
static int
vscan_drv_open(dev_t *devp, int flag, int otyp, cred_t *credp)
{
	int rc;
	int inst = getminor(*devp);

	if ((inst < 0) || (inst > vs_nodes_max))
		return (EINVAL);

	/* check if caller has privilege for virus scanning */
	if ((rc = secpolicy_vscan(credp)) != 0) {
		DTRACE_PROBE1(vscan__priv, int, rc);
		return (EPERM);
	}

	mutex_enter(&vscan_drv_mutex);
	if (inst == 0) {
		switch (vscan_drv_state) {
		case VS_DRV_IDLE:
			vscan_drv_state = VS_DRV_CONNECTED;
			break;
		case VS_DRV_DELAYED_DISABLE:
			cv_signal(&vscan_drv_cv);
			vscan_drv_state = VS_DRV_CONNECTED;
			break;
		default:
			DTRACE_PROBE1(vscan__drv__state__violation,
			    int, vscan_drv_state);
			mutex_exit(&vscan_drv_mutex);
			return (EINVAL);
		}
	} else {
		if ((vscan_drv_state != VS_DRV_ENABLED) ||
		    (vscan_drv_inst_state[inst] != VS_DRV_INST_INIT)) {
			mutex_exit(&vscan_drv_mutex);
			return (EINVAL);
		}
		vscan_drv_inst_state[inst] = VS_DRV_INST_OPEN;
	}
	mutex_exit(&vscan_drv_mutex);

	return (0);
}


/*
 * vscan_drv_close
 *
 * If inst == 0, this is vscand detaching.
 * If the driver is in ENABLED state vscand has terminated without
 * a clean shutdown (nod DISABLE received). Enter DELAYED_DISABLE
 * state and initiate a delayed disable to allow vscand time to
 * reconnect.
 *
 * If inst != 0, close the file associated with inst
 */
/* ARGSUSED */
static int
vscan_drv_close(dev_t dev, int flag, int otyp, cred_t *credp)
{
	int i, inst = getminor(dev);

	if ((inst < 0) || (inst > vs_nodes_max))
		return (EINVAL);

	mutex_enter(&vscan_drv_mutex);
	if (inst != 0) {
		vscan_drv_inst_state[inst] = VS_DRV_INST_INIT;
		mutex_exit(&vscan_drv_mutex);
		return (0);
	}

	/* instance 0 - daemon disconnect */
	if ((vscan_drv_state != VS_DRV_CONNECTED) &&
	    (vscan_drv_state != VS_DRV_ENABLED)) {
		DTRACE_PROBE1(vscan__drv__state__violation,
		    int, vscan_drv_state);
		mutex_exit(&vscan_drv_mutex);
		return (EINVAL);
	}

	for (i = 1; i <= vs_nodes_max; i++) {
		if (vscan_drv_inst_state[i] != VS_DRV_INST_UNCONFIG)
			vscan_drv_inst_state[i] = VS_DRV_INST_INIT;
	}

	if (vscan_drv_state == VS_DRV_CONNECTED) {
		vscan_drv_state = VS_DRV_IDLE;
	} else { /* VS_DRV_ENABLED */
		cmn_err(CE_WARN, "Detected vscand exit without clean shutdown");
		if (thread_create(NULL, 0, vscan_drv_delayed_disable,
		    0, 0, &p0, TS_RUN, minclsyspri) == NULL) {
			vscan_svc_disable();
			vscan_drv_state = VS_DRV_IDLE;
		} else {
			vscan_drv_state = VS_DRV_DELAYED_DISABLE;
		}
	}
	mutex_exit(&vscan_drv_mutex);

	vscan_svc_scan_abort();
	vscan_door_close();
	return (0);
}


/*
 * vscan_drv_delayed_disable
 *
 * Invoked from vscan_drv_close if the daemon disconnects
 * without first sending disable (e.g. daemon crashed).
 * Delays for vs_reconnect_timeout before disabling, to allow
 * the daemon to reconnect. During this time, scan requests
 * will be processed locally (see vscan_svc.c)
 */
static void
vscan_drv_delayed_disable(void)
{
	mutex_enter(&vscan_drv_mutex);
	(void) cv_reltimedwait(&vscan_drv_cv, &vscan_drv_mutex,
	    SEC_TO_TICK(vs_reconnect_timeout), TR_CLOCK_TICK);

	if (vscan_drv_state == VS_DRV_DELAYED_DISABLE) {
		vscan_svc_disable();
		vscan_drv_state = VS_DRV_IDLE;
	} else {
		DTRACE_PROBE(vscan__reconnect);
	}
	mutex_exit(&vscan_drv_mutex);
}


/*
 * vscan_drv_read
 */
/* ARGSUSED */
static int
vscan_drv_read(dev_t dev, struct uio *uiop, cred_t *credp)
{
	int rc;
	int inst = getminor(dev);
	vnode_t *vp;

	if ((inst <= 0) || (inst > vs_nodes_max))
		return (EINVAL);

	mutex_enter(&vscan_drv_mutex);
	if ((vscan_drv_state != VS_DRV_ENABLED) ||
	    (vscan_drv_inst_state[inst] != VS_DRV_INST_OPEN)) {
		mutex_exit(&vscan_drv_mutex);
		return (EINVAL);
	}
	vscan_drv_inst_state[inst] = VS_DRV_INST_READING;
	mutex_exit(&vscan_drv_mutex);

	if ((vp = vscan_svc_get_vnode(inst)) == NULL)
		return (EINVAL);

	(void) VOP_RWLOCK(vp, V_WRITELOCK_FALSE, NULL);
	rc = VOP_READ(vp, uiop, 0, kcred, NULL);
	VOP_RWUNLOCK(vp, V_WRITELOCK_FALSE, NULL);

	mutex_enter(&vscan_drv_mutex);
	if (vscan_drv_inst_state[inst] == VS_DRV_INST_READING)
		vscan_drv_inst_state[inst] = VS_DRV_INST_OPEN;
	mutex_exit(&vscan_drv_mutex);

	return (rc);
}


/*
 * vscan_drv_ioctl
 *
 * Process ioctls from vscand:
 * VS_IOCTL_ENABLE - vscand is ready to handle scan requests,
 *    enable VFS interface.
 * VS_IOCTL_DISABLE - vscand is shutting down, disable VFS interface
 * VS_IOCTL_RESULT - scan response data
 * VS_IOCTL_CONFIG - configuration data from vscand
 * VS_IOCTL_MAX_REQ - provide the max request idx to vscand,
 *    to allow vscand to set appropriate resource allocation limits
 */
/* ARGSUSED */
static int
vscan_drv_ioctl(dev_t dev, int cmd, intptr_t arg, int mode,
	cred_t *credp, int *rvalp)
{
	int inst = getminor(dev);
	vs_config_t conf;
	vs_scan_rsp_t rsp;

	if (inst != 0)
		return (EINVAL);

	switch (cmd) {
	case VS_IOCTL_ENABLE:
		mutex_enter(&vscan_drv_mutex);
		if (vscan_drv_state != VS_DRV_CONNECTED) {
			DTRACE_PROBE1(vscan__drv__state__violation,
			    int, vscan_drv_state);
			mutex_exit(&vscan_drv_mutex);
			return (EINVAL);
		}
		if ((vscan_door_open((int)arg) != 0) ||
		    (vscan_svc_enable() != 0)) {
			mutex_exit(&vscan_drv_mutex);
			return (EINVAL);
		}
		vscan_drv_state = VS_DRV_ENABLED;
		mutex_exit(&vscan_drv_mutex);
		break;

	case VS_IOCTL_DISABLE:
		mutex_enter(&vscan_drv_mutex);
		if (vscan_drv_state != VS_DRV_ENABLED) {
			DTRACE_PROBE1(vscan__drv__state__violation,
			    int, vscan_drv_state);
			mutex_exit(&vscan_drv_mutex);
			return (EINVAL);
		}
		vscan_svc_disable();
		vscan_drv_state = VS_DRV_CONNECTED;
		mutex_exit(&vscan_drv_mutex);
		break;

	case VS_IOCTL_RESULT:
		if (ddi_copyin((void *)arg, &rsp,
		    sizeof (vs_scan_rsp_t), 0) == -1)
			return (EFAULT);
		else
			vscan_svc_scan_result(&rsp);
		break;

	case VS_IOCTL_CONFIG:
		if (ddi_copyin((void *)arg, &conf,
		    sizeof (vs_config_t), 0) == -1)
			return (EFAULT);
		if (vscan_svc_configure(&conf) == -1)
			return (EINVAL);
		break;

	case VS_IOCTL_MAX_REQ:
		if (ddi_copyout(&vs_nodes_max, (void *)arg,
		    sizeof (uint32_t), 0) == -1)
			return (EFAULT);
		break;

	default:
		return (ENOTTY);
	}

	return (0);
}


/*
 * vscan_drv_create_node
 *
 * Create minor node with which vscan daemon will communicate
 * to access a file. Invoked from vscan_svc before scan request
 * sent up to daemon.
 * Minor node 0 is reserved for daemon-driver synchronization
 * and is created during attach.
 * All minor nodes are removed during detach.
 */
boolean_t
vscan_drv_create_node(int idx)
{
	char name[VS_NODENAME_LEN];
	boolean_t rc = B_TRUE;

	mutex_enter(&vscan_drv_mutex);

	if (vscan_drv_inst_state[idx] == VS_DRV_INST_UNCONFIG) {
		(void) snprintf(name, VS_NODENAME_LEN, "vscan%d", idx);
		if (ddi_create_minor_node(vscan_drv_dip, name,
		    S_IFCHR, idx, DDI_PSEUDO, 0) == DDI_SUCCESS) {
			vscan_drv_inst_state[idx] = VS_DRV_INST_INIT;
		} else {
			rc = B_FALSE;
		}
		DTRACE_PROBE2(vscan__minor__node, int, idx, int, rc);
	}

	mutex_exit(&vscan_drv_mutex);

	return (rc);
}