1 /* Copyright (c) 2006 Coraid, Inc. See COPYING for GPL terms. */
4 * AoE device utility functions; maintains device list.
7 #include <linux/hdreg.h>
8 #include <linux/blkdev.h>
9 #include <linux/netdevice.h>
12 static struct aoedev
*devlist
;
13 static spinlock_t devlist_lock
;
16 aoedev_isbusy(struct aoedev
*d
)
23 if (f
->tag
!= FREETAG
)
31 aoedev_by_aoeaddr(int maj
, int min
)
36 spin_lock_irqsave(&devlist_lock
, flags
);
38 for (d
=devlist
; d
; d
=d
->next
)
39 if (d
->aoemajor
== maj
&& d
->aoeminor
== min
)
42 spin_unlock_irqrestore(&devlist_lock
, flags
);
51 d
= (struct aoedev
*)vp
;
52 if (d
->flags
& DEVFL_TKILL
)
54 d
->timer
.expires
= jiffies
+ HZ
;
58 /* called with devlist lock held */
59 static struct aoedev
*
60 aoedev_newdev(ulong nframes
)
65 d
= kzalloc(sizeof *d
, GFP_ATOMIC
);
68 f
= kcalloc(nframes
, sizeof *f
, GFP_ATOMIC
);
74 INIT_WORK(&d
->work
, aoecmd_sleepwork
, d
);
82 spin_lock_init(&d
->lock
);
83 init_timer(&d
->timer
);
84 d
->timer
.data
= (ulong
) d
;
85 d
->timer
.function
= dummy_timer
;
86 d
->timer
.expires
= jiffies
+ HZ
;
88 d
->bufpool
= NULL
; /* defer to aoeblk_gdalloc */
89 INIT_LIST_HEAD(&d
->bufq
);
97 aoedev_downdev(struct aoedev
*d
)
105 for (; f
<e
; f
->tag
= FREETAG
, f
->buf
= NULL
, f
++) {
106 if (f
->tag
== FREETAG
|| f
->buf
== NULL
)
110 if (--buf
->nframesout
== 0) {
111 mempool_free(buf
, d
->bufpool
);
112 bio_endio(bio
, bio
->bi_size
, -EIO
);
117 while (!list_empty(&d
->bufq
)) {
118 buf
= container_of(d
->bufq
.next
, struct buf
, bufs
);
119 list_del(d
->bufq
.next
);
121 mempool_free(buf
, d
->bufpool
);
122 bio_endio(bio
, bio
->bi_size
, -EIO
);
128 d
->flags
&= ~(DEVFL_UP
| DEVFL_PAUSE
);
131 /* find it or malloc it */
133 aoedev_by_sysminor_m(ulong sysminor
, ulong bufcnt
)
138 spin_lock_irqsave(&devlist_lock
, flags
);
140 for (d
=devlist
; d
; d
=d
->next
)
141 if (d
->sysminor
== sysminor
)
145 d
= aoedev_newdev(bufcnt
);
147 spin_unlock_irqrestore(&devlist_lock
, flags
);
148 printk(KERN_INFO
"aoe: aoedev_set: aoedev_newdev failure.\n");
151 d
->sysminor
= sysminor
;
152 d
->aoemajor
= AOEMAJOR(sysminor
);
153 d
->aoeminor
= AOEMINOR(sysminor
);
156 spin_unlock_irqrestore(&devlist_lock
, flags
);
161 aoedev_freedev(struct aoedev
*d
)
170 mempool_destroy(d
->bufpool
);
180 flush_scheduled_work();
182 while ((d
= devlist
)) {
185 spin_lock_irqsave(&d
->lock
, flags
);
187 d
->flags
|= DEVFL_TKILL
;
188 spin_unlock_irqrestore(&d
->lock
, flags
);
190 del_timer_sync(&d
->timer
);
198 spin_lock_init(&devlist_lock
);
This page took 0.037591 seconds and 6 git commands to generate.