4 * Copyright (c) 2008 Juan Romero Pardines.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include <sys/cdefs.h>
29 __KERNEL_RCSID(0, "$NetBSD$");
31 #include <sys/param.h>
32 #include <sys/systm.h>
34 #include <sys/kernel.h>
37 #include <sys/disklabel.h>
38 #include <sys/fcntl.h>
39 #include <sys/vnode.h>
40 #include <sys/kauth.h>
43 #include <dev/ata/ata_raidvar.h>
45 struct ataraid_disk_vnode
{
46 struct ataraid_disk_info
*adv_adi
;
47 struct vnode
*adv_vnode
;
48 SLIST_ENTRY(ataraid_disk_vnode
) adv_next
;
51 static SLIST_HEAD(, ataraid_disk_vnode
) ataraid_disk_vnode_list
=
52 SLIST_HEAD_INITIALIZER(ataraid_disk_vnode_list
);
55 * Finds the RAW_PART vnode of the block device associated with a component
56 * by looking at the singly linked list; otherwise creates, opens and
57 * returns the vnode to the caller.
60 ata_raid_disk_vnode_find(struct ataraid_disk_info
*adi
)
62 struct ataraid_disk_vnode
*adv
= NULL
;
63 struct vnode
*vp
= NULL
;
65 int bmajor
, error
= 0;
68 SLIST_FOREACH(adv
, &ataraid_disk_vnode_list
, adv_next
) {
69 devlist
= adv
->adv_adi
->adi_dev
;
70 if (strcmp(device_xname(devlist
),
71 device_xname(adi
->adi_dev
)) == 0)
72 return adv
->adv_vnode
;
76 adv
= kmem_zalloc(sizeof(struct ataraid_disk_vnode
), KM_SLEEP
);
78 bmajor
= devsw_name2blk(device_xname(adi
->adi_dev
), NULL
, 0);
79 dev
= MAKEDISKDEV(bmajor
, device_unit(adi
->adi_dev
), RAW_PART
);
81 error
= bdevvp(dev
, &vp
);
83 kmem_free(adv
, sizeof(struct ataraid_disk_vnode
));
86 error
= VOP_OPEN(vp
, FREAD
|FWRITE
, NOCRED
);
89 kmem_free(adv
, sizeof(struct ataraid_disk_vnode
));
92 vn_lock(vp
, LK_EXCLUSIVE
| LK_RETRY
);
98 SLIST_INSERT_HEAD(&ataraid_disk_vnode_list
, adv
, adv_next
);
100 return adv
->adv_vnode
;