···630630 }631631632632 case NBD_CLEAR_SOCK: {633633- struct file *file;634634-633633+ struct socket *sock = nbd->sock;635634 nbd->sock = NULL;636636- file = nbd->file;637637- nbd->file = NULL;638635 nbd_clear_que(nbd);639636 BUG_ON(!list_empty(&nbd->queue_head));640637 BUG_ON(!list_empty(&nbd->waiting_queue));641638 kill_bdev(bdev);642642- if (file)643643- fput(file);639639+ if (sock)640640+ sockfd_put(sock);644641 return 0;645642 }646643647644 case NBD_SET_SOCK: {648648- struct file *file;649649- if (nbd->file)645645+ struct socket *sock;646646+ int err;647647+ if (nbd->sock)650648 return -EBUSY;651651- file = fget(arg);652652- if (file) {653653- struct inode *inode = file_inode(file);654654- if (S_ISSOCK(inode->i_mode)) {655655- nbd->file = file;656656- nbd->sock = SOCKET_I(inode);657657- if (max_part > 0)658658- bdev->bd_invalidated = 1;659659- nbd->disconnect = 0; /* we're connected now */660660- return 0;661661- } else {662662- fput(file);663663- }649649+ sock = sockfd_lookup(arg, &err);650650+ if (sock) {651651+ nbd->sock = sock;652652+ if (max_part > 0)653653+ bdev->bd_invalidated = 1;654654+ nbd->disconnect = 0; /* we're connected now */655655+ return 0;664656 }665657 return -EINVAL;666658 }···689697690698 case NBD_DO_IT: {691699 struct task_struct *thread;692692- struct file *file;700700+ struct socket *sock;693701 int error;694702695703 if (nbd->pid)696704 return -EBUSY;697697- if (!nbd->file)705705+ if (!nbd->sock)698706 return -EINVAL;699707700708 mutex_unlock(&nbd->tx_lock);···723731 if (error)724732 return error;725733 sock_shutdown(nbd, 0);726726- file = nbd->file;727727- nbd->file = NULL;734734+ sock = nbd->sock;735735+ nbd->sock = NULL;728736 nbd_clear_que(nbd);729737 dev_warn(disk_to_dev(nbd->disk), "queue cleared\n");730738 kill_bdev(bdev);731739 queue_flag_clear_unlocked(QUEUE_FLAG_DISCARD, nbd->disk->queue);732740 set_device_ro(bdev, false);733733- if (file)734734- fput(file);741741+ if (sock)742742+ sockfd_put(sock);735743 nbd->flags = 0;736744 nbd->bytesize = 0;737745 bdev->bd_inode->i_size = 0;···867875868876 for (i = 0; i < nbds_max; i++) {869877 struct gendisk *disk = nbd_dev[i].disk;870870- nbd_dev[i].file = NULL;871878 nbd_dev[i].magic = NBD_MAGIC;872872- nbd_dev[i].flags = 0;873879 INIT_LIST_HEAD(&nbd_dev[i].waiting_queue);874880 spin_lock_init(&nbd_dev[i].queue_lock);875881 INIT_LIST_HEAD(&nbd_dev[i].queue_head);
+1-2
include/linux/nbd.h
···2424struct nbd_device {2525 int flags;2626 int harderror; /* Code of hard error */2727- struct socket * sock;2828- struct file * file; /* If == NULL, device is not ready, yet */2727+ struct socket * sock; /* If == NULL, device is not ready, yet */2928 int magic;30293130 spinlock_t queue_lock;