Lines Matching refs:bd
26 #define bsg_dbg(bd, fmt, ...) \
27 pr_debug("%s: " fmt, (bd)->name, ##__VA_ARGS__)
200 struct bsg_device *bd;
202 bd = kzalloc(sizeof(struct bsg_device), GFP_KERNEL);
203 if (unlikely(!bd))
206 spin_lock_init(&bd->lock);
207 bd->max_queue = BSG_DEFAULT_CMDS;
208 INIT_HLIST_NODE(&bd->dev_list);
209 return bd;
212 static int bsg_put_device(struct bsg_device *bd)
214 struct request_queue *q = bd->queue;
218 if (!refcount_dec_and_test(&bd->ref_count)) {
223 hlist_del(&bd->dev_list);
226 bsg_dbg(bd, "tearing down\n");
231 kfree(bd);
240 struct bsg_device *bd;
248 bd = bsg_alloc_device();
249 if (!bd) {
254 bd->queue = rq;
256 refcount_set(&bd->ref_count, 1);
257 hlist_add_head(&bd->dev_list, bsg_dev_idx_hash(iminor(inode)));
259 strncpy(bd->name, dev_name(rq->bsg_dev.class_dev), sizeof(bd->name) - 1);
260 bsg_dbg(bd, "bound to <%s>, max queue %d\n",
261 format_dev_t(buf, inode->i_rdev), bd->max_queue);
263 return bd;
268 struct bsg_device *bd;
272 hlist_for_each_entry(bd, bsg_dev_idx_hash(minor), dev_list) {
273 if (bd->queue == q) {
274 refcount_inc(&bd->ref_count);
278 bd = NULL;
280 return bd;
285 struct bsg_device *bd;
295 bd = ERR_PTR(-ENODEV);
299 bd = __bsg_get_device(iminor(inode), bcd->queue);
300 if (!bd)
301 bd = bsg_add_device(inode, bcd->queue, file);
305 return bd;
310 struct bsg_device *bd;
312 bd = bsg_get_device(inode, file);
314 if (IS_ERR(bd))
315 return PTR_ERR(bd);
317 file->private_data = bd;
323 struct bsg_device *bd = file->private_data;
326 return bsg_put_device(bd);
329 static int bsg_get_command_q(struct bsg_device *bd, int __user *uarg)
331 return put_user(bd->max_queue, uarg);
334 static int bsg_set_command_q(struct bsg_device *bd, int __user *uarg)
343 spin_lock_irq(&bd->lock);
344 bd->max_queue = queue;
345 spin_unlock_irq(&bd->lock);
351 struct bsg_device *bd = file->private_data;
359 return bsg_get_command_q(bd, uarg);
361 return bsg_set_command_q(bd, uarg);
374 return scsi_cmd_ioctl(bd->queue, NULL, file->f_mode, cmd, uarg);
376 return bsg_sg_io(bd->queue, file->f_mode, uarg);