Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1412350 > unrolled thread
| Started by | "Pranay Kr. Srivastava" <pranjas@gmail.com> |
|---|---|
| First post | 2016-06-02 17:30 +0200 |
| Last post | 2016-06-06 13:10 +0200 |
| Articles | 8 — 2 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[PATCH v2 0/5] nbd: fixes for nbd "Pranay Kr. Srivastava" <pranjas@gmail.com> - 2016-06-02 17:30 +0200
[PATCH v2 1/5] nbd: fix might_sleep warning on socket shutdown. "Pranay Kr. Srivastava" <pranjas@gmail.com> - 2016-06-02 17:30 +0200
Re: [PATCH v2 1/5] nbd: fix might_sleep warning on socket shutdown. Pranay Srivastava <pranjas@gmail.com> - 2016-06-09 12:10 +0200
[PATCH v2 4/5]nbd: make nbd device wait for its users. "Pranay Kr. Srivastava" <pranjas@gmail.com> - 2016-06-02 17:30 +0200
[PATCH v2 2/5]nbd: cleanup nbd_set_socket "Pranay Kr. Srivastava" <pranjas@gmail.com> - 2016-06-02 17:30 +0200
[PATCH v2 5/5]nbd: use device_attr macros for sysfs attribute "Pranay Kr. Srivastava" <pranjas@gmail.com> - 2016-06-02 17:30 +0200
[PATCH v2 3/5]nbd: fix various coding standard warnings "Pranay Kr. Srivastava" <pranjas@gmail.com> - 2016-06-02 17:30 +0200
Re: [PATCH 0/4]nbd: fixes for nbd Pranay Srivastava <pranjas@gmail.com> - 2016-06-06 13:10 +0200
| From | "Pranay Kr. Srivastava" <pranjas@gmail.com> |
|---|---|
| Date | 2016-06-02 17:30 +0200 |
| Subject | [PATCH v2 0/5] nbd: fixes for nbd |
| Message-ID | <rFCJj-7Au-9@gated-at.bofh.it> |
This patch series fixes the following 1) fix might_sleep warning on socket shutdown: Fix sock_shutdown to avoid calling kernel_sock_shutdown while holding spin_lock. 2) cleanup nbd_set_socket Cleanup nbd_set_socket to use spin_lock instead of irq version and remove the goto statement in favour of a simple if-else statement. 3) fix various coding standard warnings Make shutdown get called in a process context instead, using system_wq. 4) make nbd device wait for its users. When a timeout or error occurs then nbd driver simply kills the block device. Many filesystem(s) example ext2/ext3 don't expect their buffer heads to disappear like that. Fix this by making nbd device wait for its users. Introduced a new field to check if the device is currently in use or not. This helps to check if the kref_put should be done on device release or not. This field needs to be atomic as the release function may be called from NBD_DO_IT as well as from device's release function. 5) use device_attr macros for sysfs attribute use DEVICE_ATTR_RO for sysfs pid attribute. Changelog for v2: 1) fix might_sleep warning on socket shutdown use bool timedout instead of atomic 2) cleanup nbd_set_socket Added this new patch to this series. 3) fix various coding standard warnings No Change. 4) make nbd device wait for its users Earlier version used to do a final kref put when the kref->counter == 2. This required a check of the internal atomic counter of kref which was ugly. v2 of this patch make this more readable and doesn't do manual check of the internal counter used by kref. 5) use device_attr macros for sysfs attribute No Change. Pranay Kr. Srivastava (5): fix might_sleep warning on socket shutdown. cleanup nbd_set_socket fix various coding standard warnings make nbd device wait for its users. use device_attr macros for sysfs attribute drivers/block/nbd.c | 173 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 124 insertions(+), 49 deletions(-) -- 2.6.2
[toc] | [next] | [standalone]
| From | "Pranay Kr. Srivastava" <pranjas@gmail.com> |
|---|---|
| Date | 2016-06-02 17:30 +0200 |
| Subject | [PATCH v2 1/5] nbd: fix might_sleep warning on socket shutdown. |
| Message-ID | <rFCJj-7Au-13@gated-at.bofh.it> |
| In reply to | #1412350 |
spinlocked ranges should be small and not contain calls into huge
subfunctions. Fix my mistake and just get the pointer to the socket
instead of doing everything with spinlock held.
Reported-by: Mikulas Patocka <mikulas@twibright.com>
Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
Changelog:
Pranay Kr. Srivastava<pranjas@gmail.com>:
1) Use spin_lock instead of irq version for sock_shutdown.
2) Use system work queue to actually trigger the shutdown of
socket. This solves the issue when kernel_sendmsg is currently
blocked while a timeout occurs.
Signed-off-by: Pranay Kr. Srivastava <pranjas@gmail.com>
---
drivers/block/nbd.c | 65 ++++++++++++++++++++++++++++++++++-------------------
1 file changed, 42 insertions(+), 23 deletions(-)
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 31e73a7..0339d40 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -39,6 +39,7 @@
#include <asm/types.h>
#include <linux/nbd.h>
+#include <linux/workqueue.h>
struct nbd_device {
u32 flags;
@@ -69,6 +70,10 @@ struct nbd_device {
#if IS_ENABLED(CONFIG_DEBUG_FS)
struct dentry *dbg_dir;
#endif
+ /*
+ *This is specifically for calling sock_shutdown, for now.
+ */
+ struct work_struct ws_shutdown;
};
#if IS_ENABLED(CONFIG_DEBUG_FS)
@@ -95,6 +100,11 @@ static int max_part;
*/
static DEFINE_SPINLOCK(nbd_lock);
+/*
+ * Shutdown function for nbd_dev work struct.
+ */
+static void nbd_ws_func_shutdown(struct work_struct *);
+
static inline struct device *nbd_to_dev(struct nbd_device *nbd)
{
return disk_to_dev(nbd->disk);
@@ -172,39 +182,35 @@ static void nbd_end_request(struct nbd_device *nbd, struct request *req)
*/
static void sock_shutdown(struct nbd_device *nbd)
{
- spin_lock_irq(&nbd->sock_lock);
-
- if (!nbd->sock) {
- spin_unlock_irq(&nbd->sock_lock);
- return;
- }
+ struct socket *sock;
- dev_warn(disk_to_dev(nbd->disk), "shutting down socket\n");
- kernel_sock_shutdown(nbd->sock, SHUT_RDWR);
- sockfd_put(nbd->sock);
+ spin_lock(&nbd->sock_lock);
+ sock = nbd->sock;
nbd->sock = NULL;
- spin_unlock_irq(&nbd->sock_lock);
+ spin_unlock(&nbd->sock_lock);
+
+ if (!sock)
+ return;
del_timer(&nbd->timeout_timer);
+ dev_warn(disk_to_dev(nbd->disk), "shutting down socket\n");
+ kernel_sock_shutdown(sock, SHUT_RDWR);
+ sockfd_put(sock);
}
static void nbd_xmit_timeout(unsigned long arg)
{
struct nbd_device *nbd = (struct nbd_device *)arg;
- unsigned long flags;
if (list_empty(&nbd->queue_head))
return;
-
- spin_lock_irqsave(&nbd->sock_lock, flags);
-
nbd->timedout = true;
-
- if (nbd->sock)
- kernel_sock_shutdown(nbd->sock, SHUT_RDWR);
-
- spin_unlock_irqrestore(&nbd->sock_lock, flags);
-
+ schedule_work(&nbd->ws_shutdown);
+ /*
+ * Make sure sender thread sees nbd->timedout.
+ */
+ smp_wmb();
+ wake_up(&nbd->waiting_wq);
dev_err(nbd_to_dev(nbd), "Connection timed out, shutting down connection\n");
}
@@ -592,7 +598,11 @@ static int nbd_thread_send(void *data)
spin_unlock_irq(&nbd->queue_lock);
/* handle request */
- nbd_handle_req(nbd, req);
+ if (nbd->timedout) {
+ req->errors++;
+ nbd_end_request(nbd, req);
+ } else
+ nbd_handle_req(nbd, req);
}
nbd->task_send = NULL;
@@ -672,6 +682,7 @@ static void nbd_reset(struct nbd_device *nbd)
set_capacity(nbd->disk, 0);
nbd->flags = 0;
nbd->xmit_timeout = 0;
+ INIT_WORK(&nbd->ws_shutdown, nbd_ws_func_shutdown);
queue_flag_clear_unlocked(QUEUE_FLAG_DISCARD, nbd->disk->queue);
del_timer_sync(&nbd->timeout_timer);
}
@@ -804,15 +815,15 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd,
nbd_dev_dbg_close(nbd);
kthread_stop(thread);
- mutex_lock(&nbd->tx_lock);
-
sock_shutdown(nbd);
+ mutex_lock(&nbd->tx_lock);
nbd_clear_que(nbd);
kill_bdev(bdev);
nbd_bdev_reset(bdev);
if (nbd->disconnect) /* user requested, ignore socket errors */
error = 0;
+
if (nbd->timedout)
error = -ETIMEDOUT;
@@ -863,6 +874,14 @@ static const struct block_device_operations nbd_fops =
.compat_ioctl = nbd_ioctl,
};
+static void nbd_ws_func_shutdown(struct work_struct *ws_nbd)
+{
+ struct nbd_device *nbd_dev = container_of(ws_nbd, struct nbd_device,
+ ws_shutdown);
+
+ sock_shutdown(nbd_dev);
+}
+
#if IS_ENABLED(CONFIG_DEBUG_FS)
static int nbd_dbg_tasks_show(struct seq_file *s, void *unused)
--
2.6.2
[toc] | [prev] | [next] | [standalone]
| From | Pranay Srivastava <pranjas@gmail.com> |
|---|---|
| Date | 2016-06-09 12:10 +0200 |
| Subject | Re: [PATCH v2 1/5] nbd: fix might_sleep warning on socket shutdown. |
| Message-ID | <rI54u-4W8-7@gated-at.bofh.it> |
| In reply to | #1412351 |
Hello
On Thu, Jun 2, 2016 at 3:54 PM, Pranay Kr. Srivastava <pranjas@gmail.com> wrote:
> spinlocked ranges should be small and not contain calls into huge
> subfunctions. Fix my mistake and just get the pointer to the socket
> instead of doing everything with spinlock held.
>
> Reported-by: Mikulas Patocka <mikulas@twibright.com>
> Signed-off-by: Markus Pargmann <mpa@pengutronix.de>
>
> Changelog:
> Pranay Kr. Srivastava<pranjas@gmail.com>:
>
> 1) Use spin_lock instead of irq version for sock_shutdown.
>
> 2) Use system work queue to actually trigger the shutdown of
> socket. This solves the issue when kernel_sendmsg is currently
> blocked while a timeout occurs.
>
> Signed-off-by: Pranay Kr. Srivastava <pranjas@gmail.com>
> ---
> drivers/block/nbd.c | 65 ++++++++++++++++++++++++++++++++++-------------------
> 1 file changed, 42 insertions(+), 23 deletions(-)
>
> diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
> index 31e73a7..0339d40 100644
> --- a/drivers/block/nbd.c
> +++ b/drivers/block/nbd.c
> @@ -39,6 +39,7 @@
> #include <asm/types.h>
>
> #include <linux/nbd.h>
> +#include <linux/workqueue.h>
>
> struct nbd_device {
> u32 flags;
> @@ -69,6 +70,10 @@ struct nbd_device {
> #if IS_ENABLED(CONFIG_DEBUG_FS)
> struct dentry *dbg_dir;
> #endif
> + /*
> + *This is specifically for calling sock_shutdown, for now.
> + */
> + struct work_struct ws_shutdown;
> };
>
> #if IS_ENABLED(CONFIG_DEBUG_FS)
> @@ -95,6 +100,11 @@ static int max_part;
> */
> static DEFINE_SPINLOCK(nbd_lock);
>
> +/*
> + * Shutdown function for nbd_dev work struct.
> + */
> +static void nbd_ws_func_shutdown(struct work_struct *);
> +
> static inline struct device *nbd_to_dev(struct nbd_device *nbd)
> {
> return disk_to_dev(nbd->disk);
> @@ -172,39 +182,35 @@ static void nbd_end_request(struct nbd_device *nbd, struct request *req)
> */
> static void sock_shutdown(struct nbd_device *nbd)
> {
> - spin_lock_irq(&nbd->sock_lock);
> -
> - if (!nbd->sock) {
> - spin_unlock_irq(&nbd->sock_lock);
> - return;
> - }
> + struct socket *sock;
>
> - dev_warn(disk_to_dev(nbd->disk), "shutting down socket\n");
> - kernel_sock_shutdown(nbd->sock, SHUT_RDWR);
> - sockfd_put(nbd->sock);
> + spin_lock(&nbd->sock_lock);
> + sock = nbd->sock;
> nbd->sock = NULL;
> - spin_unlock_irq(&nbd->sock_lock);
> + spin_unlock(&nbd->sock_lock);
> +
> + if (!sock)
> + return;
>
> del_timer(&nbd->timeout_timer);
> + dev_warn(disk_to_dev(nbd->disk), "shutting down socket\n");
> + kernel_sock_shutdown(sock, SHUT_RDWR);
> + sockfd_put(sock);
> }
>
> static void nbd_xmit_timeout(unsigned long arg)
> {
> struct nbd_device *nbd = (struct nbd_device *)arg;
> - unsigned long flags;
>
> if (list_empty(&nbd->queue_head))
> return;
> -
> - spin_lock_irqsave(&nbd->sock_lock, flags);
> -
> nbd->timedout = true;
> -
> - if (nbd->sock)
> - kernel_sock_shutdown(nbd->sock, SHUT_RDWR);
> -
> - spin_unlock_irqrestore(&nbd->sock_lock, flags);
> -
> + schedule_work(&nbd->ws_shutdown);
> + /*
> + * Make sure sender thread sees nbd->timedout.
> + */
> + smp_wmb();
> + wake_up(&nbd->waiting_wq);
> dev_err(nbd_to_dev(nbd), "Connection timed out, shutting down connection\n");
> }
>
> @@ -592,7 +598,11 @@ static int nbd_thread_send(void *data)
> spin_unlock_irq(&nbd->queue_lock);
>
> /* handle request */
> - nbd_handle_req(nbd, req);
> + if (nbd->timedout) {
> + req->errors++;
> + nbd_end_request(nbd, req);
> + } else
> + nbd_handle_req(nbd, req);
> }
>
> nbd->task_send = NULL;
> @@ -672,6 +682,7 @@ static void nbd_reset(struct nbd_device *nbd)
> set_capacity(nbd->disk, 0);
> nbd->flags = 0;
> nbd->xmit_timeout = 0;
> + INIT_WORK(&nbd->ws_shutdown, nbd_ws_func_shutdown);
> queue_flag_clear_unlocked(QUEUE_FLAG_DISCARD, nbd->disk->queue);
> del_timer_sync(&nbd->timeout_timer);
> }
> @@ -804,15 +815,15 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd,
> nbd_dev_dbg_close(nbd);
> kthread_stop(thread);
>
> - mutex_lock(&nbd->tx_lock);
> -
> sock_shutdown(nbd);
> + mutex_lock(&nbd->tx_lock);
> nbd_clear_que(nbd);
> kill_bdev(bdev);
> nbd_bdev_reset(bdev);
>
> if (nbd->disconnect) /* user requested, ignore socket errors */
> error = 0;
> +
> if (nbd->timedout)
> error = -ETIMEDOUT;
>
> @@ -863,6 +874,14 @@ static const struct block_device_operations nbd_fops =
> .compat_ioctl = nbd_ioctl,
> };
>
> +static void nbd_ws_func_shutdown(struct work_struct *ws_nbd)
> +{
> + struct nbd_device *nbd_dev = container_of(ws_nbd, struct nbd_device,
> + ws_shutdown);
> +
> + sock_shutdown(nbd_dev);
> +}
> +
> #if IS_ENABLED(CONFIG_DEBUG_FS)
>
> static int nbd_dbg_tasks_show(struct seq_file *s, void *unused)
> --
> 2.6.2
>
Any update for the above patch series?
--
---P.K.S
[toc] | [prev] | [next] | [standalone]
| From | "Pranay Kr. Srivastava" <pranjas@gmail.com> |
|---|---|
| Date | 2016-06-02 17:30 +0200 |
| Subject | [PATCH v2 4/5]nbd: make nbd device wait for its users. |
| Message-ID | <rFCJk-7Au-15@gated-at.bofh.it> |
| In reply to | #1412350 |
When a timeout occurs or a recv fails, then
instead of abruplty killing nbd block device
wait for it's users to finish.
This is more required when filesystem(s) like
ext2 or ext3 don't expect their buffer heads to
disappear while the filesystem is mounted.
Each open of a nbd device is refcounted, while
the userland program [nbd-client] doing the
NBD_DO_IT ioctl would now wait for any other users
of this device before invalidating the nbd device.
Signed-off-by: Pranay Kr. Srivastava <pranjas@gmail.com>
---
drivers/block/nbd.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 58 insertions(+)
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index d1d898d..4da40dc 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -70,10 +70,13 @@ struct nbd_device {
#if IS_ENABLED(CONFIG_DEBUG_FS)
struct dentry *dbg_dir;
#endif
+ atomic_t inuse;
/*
*This is specifically for calling sock_shutdown, for now.
*/
struct work_struct ws_shutdown;
+ struct kref users;
+ struct completion user_completion;
};
#if IS_ENABLED(CONFIG_DEBUG_FS)
@@ -104,6 +107,7 @@ static DEFINE_SPINLOCK(nbd_lock);
* Shutdown function for nbd_dev work struct.
*/
static void nbd_ws_func_shutdown(struct work_struct *);
+static void nbd_kref_release(struct kref *);
static inline struct device *nbd_to_dev(struct nbd_device *nbd)
{
@@ -682,6 +686,8 @@ static void nbd_reset(struct nbd_device *nbd)
nbd->flags = 0;
nbd->xmit_timeout = 0;
INIT_WORK(&nbd->ws_shutdown, nbd_ws_func_shutdown);
+ init_completion(&nbd->user_completion);
+ kref_init(&nbd->users);
queue_flag_clear_unlocked(QUEUE_FLAG_DISCARD, nbd->disk->queue);
del_timer_sync(&nbd->timeout_timer);
}
@@ -815,6 +821,14 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd,
kthread_stop(thread);
sock_shutdown(nbd);
+ /*
+ * kref_init initializes with ref count as 1,
+ * nbd_client, or the user-land program executing
+ * this ioctl will make the refcount to 2[at least]
+ * so subtracting 2 from refcount.
+ */
+ kref_sub(&nbd->users, 2, nbd_kref_release);
+ wait_for_completion(&nbd->user_completion);
mutex_lock(&nbd->tx_lock);
nbd_clear_que(nbd);
kill_bdev(bdev);
@@ -865,13 +879,56 @@ static int nbd_ioctl(struct block_device *bdev, fmode_t mode,
return error;
}
+static void nbd_kref_release(struct kref *kref_users)
+{
+ struct nbd_device *nbd = container_of(kref_users, struct nbd_device,
+ users);
+ pr_debug("Releasing kref [%s]\n", __func__);
+ atomic_set(&nbd->inuse, 0);
+ complete(&nbd->user_completion);
+
+}
+
+static int nbd_open(struct block_device *bdev, fmode_t mode)
+{
+ struct nbd_device *nbd_dev = bdev->bd_disk->private_data;
+
+ if (kref_get_unless_zero(&nbd_dev->users))
+ atomic_set(&nbd_dev->inuse, 1);
+
+ pr_debug("Opening nbd_dev %s. Active users = %u\n",
+ bdev->bd_disk->disk_name,
+ atomic_read(&nbd_dev->users.refcount) - 1);
+ return 0;
+}
+
+static void nbd_release(struct gendisk *disk, fmode_t mode)
+{
+ struct nbd_device *nbd_dev = disk->private_data;
+ /*
+ *kref_init initializes ref count to 1, so we
+ *we check for refcount to be 2 for a final put.
+ *
+ *kref needs to be re-initialized just here as the
+ *other process holding it must see the ref count as 2.
+ */
+ if (atomic_read(&nbd_dev->inuse))
+ kref_put(&nbd_dev->users, nbd_kref_release);
+
+ pr_debug("Closing nbd_dev %s. Active users = %u\n",
+ disk->disk_name,
+ atomic_read(&nbd_dev->users.refcount) - 1);
+}
static const struct block_device_operations nbd_fops = {
.owner = THIS_MODULE,
.ioctl = nbd_ioctl,
.compat_ioctl = nbd_ioctl,
+ .open = nbd_open,
+ .release = nbd_release
};
+
static void nbd_ws_func_shutdown(struct work_struct *ws_nbd)
{
struct nbd_device *nbd_dev = container_of(ws_nbd, struct nbd_device,
@@ -1107,6 +1164,7 @@ static int __init nbd_init(void)
disk->fops = &nbd_fops;
disk->private_data = &nbd_dev[i];
sprintf(disk->disk_name, "nbd%d", i);
+ atomic_set(&nbd_dev[i].inuse, 0);
nbd_reset(&nbd_dev[i]);
add_disk(disk);
}
--
2.6.2
[toc] | [prev] | [next] | [standalone]
| From | "Pranay Kr. Srivastava" <pranjas@gmail.com> |
|---|---|
| Date | 2016-06-02 17:30 +0200 |
| Subject | [PATCH v2 2/5]nbd: cleanup nbd_set_socket |
| Message-ID | <rFCJk-7Au-17@gated-at.bofh.it> |
| In reply to | #1412350 |
This patch
1) uses spin_lock instead of irq version.
2) removes the goto statement in case a socket
is already assigned with simple if-else statement.
Signed-off-by: Pranay Kr. Srivastava <pranjas@gmail.com>
---
drivers/block/nbd.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 0339d40..da2b0a4 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -657,17 +657,14 @@ static int nbd_set_socket(struct nbd_device *nbd, struct socket *sock)
{
int ret = 0;
- spin_lock_irq(&nbd->sock_lock);
+ spin_lock(&nbd->sock_lock);
- if (nbd->sock) {
+ if (nbd->sock)
ret = -EBUSY;
- goto out;
- }
-
- nbd->sock = sock;
+ else
+ nbd->sock = sock;
-out:
- spin_unlock_irq(&nbd->sock_lock);
+ spin_unlock(&nbd->sock_lock);
return ret;
}
--
2.6.2
[toc] | [prev] | [next] | [standalone]
| From | "Pranay Kr. Srivastava" <pranjas@gmail.com> |
|---|---|
| Date | 2016-06-02 17:30 +0200 |
| Subject | [PATCH v2 5/5]nbd: use device_attr macros for sysfs attribute |
| Message-ID | <rFCJk-7Au-21@gated-at.bofh.it> |
| In reply to | #1412350 |
This patch changes the pid sysfs device attribute to use
DEVICE_ATTR_* macro.
Signed-off-by: Pranay Kr. Srivastava <pranjas@gmail.com>
---
drivers/block/nbd.c | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index 4da40dc..323ab26 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -449,10 +449,8 @@ static ssize_t pid_show(struct device *dev,
return sprintf(buf, "%d\n", task_pid_nr(nbd->task_recv));
}
-static struct device_attribute pid_attr = {
- .attr = { .name = "pid", .mode = S_IRUGO},
- .show = pid_show,
-};
+
+static DEVICE_ATTR_RO(pid);
static int nbd_thread_recv(struct nbd_device *nbd, struct block_device *bdev)
{
@@ -465,7 +463,7 @@ static int nbd_thread_recv(struct nbd_device *nbd, struct block_device *bdev)
nbd->task_recv = current;
- ret = device_create_file(disk_to_dev(nbd->disk), &pid_attr);
+ ret = device_create_file(disk_to_dev(nbd->disk), &dev_attr_pid);
if (ret) {
dev_err(disk_to_dev(nbd->disk), "device_create_file failed!\n");
@@ -488,7 +486,7 @@ static int nbd_thread_recv(struct nbd_device *nbd, struct block_device *bdev)
nbd_size_clear(nbd, bdev);
- device_remove_file(disk_to_dev(nbd->disk), &pid_attr);
+ device_remove_file(disk_to_dev(nbd->disk), &dev_attr_pid);
nbd->task_recv = NULL;
--
2.6.2
[toc] | [prev] | [next] | [standalone]
| From | "Pranay Kr. Srivastava" <pranjas@gmail.com> |
|---|---|
| Date | 2016-06-02 17:30 +0200 |
| Subject | [PATCH v2 3/5]nbd: fix various coding standard warnings |
| Message-ID | <rFCJk-7Au-39@gated-at.bofh.it> |
| In reply to | #1412350 |
1 )nbd: fix checkpatch trailing space warning.
2) nbd: fix checkpatch warning use linux/uaccess.h
3) nbd : fix checkpatch pointer declaration warning
4) nbd: fix checkpatch warning no newline after decleration.
5) nbd: fix checkpatch warning no newline after decleration.
6) nbd : fix checkpatch line over 80 char warning
7) nbd: fix checkpatch trailing whitespace warning.
8) nbd: fix checkpatch trailing whitespace warning.
9) nbd : fix checkpatch structure declaration braces on next line warning.
10) nbd : fix checkpatch trailing whitespace warning
11) nbd : fix checkpatch printk warning
12) nbd: fix checkpatch no extra line after decleration warning
13) nbd: fix checkpatch printk warning to pr_info
14) nbd: fix checkpatch no new line after decleration warning
15) nbd: fix checkpatch printk warning to pr_info
Signed-off-by: Pranay Kr. Srivastava <pranjas@gmail.com>
---
drivers/block/nbd.c | 29 ++++++++++++++++-------------
1 file changed, 16 insertions(+), 13 deletions(-)
diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
index da2b0a4..d1d898d 100644
--- a/drivers/block/nbd.c
+++ b/drivers/block/nbd.c
@@ -3,7 +3,7 @@
*
* Note that you can not swap over this thing, yet. Seems to work but
* deadlocks sometimes - you can not swap over TCP in general.
- *
+ *
* Copyright 1997-2000, 2008 Pavel Machek <pavel@ucw.cz>
* Parts copyright 2001 Steven Whitehouse <steve@chygwyn.com>
*
@@ -35,7 +35,7 @@
#include <linux/types.h>
#include <linux/debugfs.h>
-#include <asm/uaccess.h>
+#include <linux/uaccess.h>
#include <asm/types.h>
#include <linux/nbd.h>
@@ -43,7 +43,7 @@
struct nbd_device {
u32 flags;
- struct socket * sock; /* If == NULL, device is not ready, yet */
+ struct socket *sock; /* If == NULL, device is not ready, yet */
int magic;
spinlock_t queue_lock;
@@ -272,6 +272,7 @@ static inline int sock_send_bvec(struct nbd_device *nbd, struct bio_vec *bvec,
{
int result;
void *kaddr = kmap(bvec->bv_page);
+
result = sock_xmit(nbd, 1, kaddr + bvec->bv_offset,
bvec->bv_len, flags);
kunmap(bvec->bv_page);
@@ -369,6 +370,7 @@ static inline int sock_recv_bvec(struct nbd_device *nbd, struct bio_vec *bvec)
{
int result;
void *kaddr = kmap(bvec->bv_page);
+
result = sock_xmit(nbd, 0, kaddr + bvec->bv_offset, bvec->bv_len,
MSG_WAITALL);
kunmap(bvec->bv_page);
@@ -611,8 +613,8 @@ static int nbd_thread_send(void *data)
}
/*
- * We always wait for result of write, for now. It would be nice to make it optional
- * in future
+ * We always wait for result of write, for now. It would be nice to make it
+ * optional in future
* if ((rq_data_dir(req) == WRITE) && (nbd->flags & NBD_WRITE_NOCHK))
* { printk( "Warning: Ignoring result!\n"); nbd_end_request( req ); }
*/
@@ -621,7 +623,7 @@ static void nbd_request_handler(struct request_queue *q)
__releases(q->queue_lock) __acquires(q->queue_lock)
{
struct request *req;
-
+
while ((req = blk_fetch_request(q)) != NULL) {
struct nbd_device *nbd;
@@ -737,7 +739,7 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd,
nbd_send_req(nbd, &sreq);
return 0;
}
-
+
case NBD_CLEAR_SOCK:
sock_shutdown(nbd);
nbd_clear_que(nbd);
@@ -864,8 +866,7 @@ static int nbd_ioctl(struct block_device *bdev, fmode_t mode,
return error;
}
-static const struct block_device_operations nbd_fops =
-{
+static const struct block_device_operations nbd_fops = {
.owner = THIS_MODULE,
.ioctl = nbd_ioctl,
.compat_ioctl = nbd_ioctl,
@@ -1008,7 +1009,7 @@ static void nbd_dbg_close(void)
#endif
/*
- * And here should be modules and kernel interface
+ * And here should be modules and kernel interface
* (Just smiley confuses emacs :-)
*/
@@ -1021,7 +1022,7 @@ static int __init nbd_init(void)
BUILD_BUG_ON(sizeof(struct nbd_request) != 28);
if (max_part < 0) {
- printk(KERN_ERR "nbd: max_part must be >= 0\n");
+ pr_err("nbd: max_part must be >= 0\n");
return -EINVAL;
}
@@ -1052,6 +1053,7 @@ static int __init nbd_init(void)
for (i = 0; i < nbds_max; i++) {
struct gendisk *disk = alloc_disk(1 << part_shift);
+
if (!disk)
goto out;
nbd_dev[i].disk = disk;
@@ -1082,12 +1084,13 @@ static int __init nbd_init(void)
goto out;
}
- printk(KERN_INFO "nbd: registered device at major %d\n", NBD_MAJOR);
+ pr_info("nbd: registered device at major %d\n", NBD_MAJOR);
nbd_dbg_init();
for (i = 0; i < nbds_max; i++) {
struct gendisk *disk = nbd_dev[i].disk;
+
nbd_dev[i].magic = NBD_MAGIC;
INIT_LIST_HEAD(&nbd_dev[i].waiting_queue);
spin_lock_init(&nbd_dev[i].queue_lock);
@@ -1135,7 +1138,7 @@ static void __exit nbd_cleanup(void)
}
unregister_blkdev(NBD_MAJOR, "nbd");
kfree(nbd_dev);
- printk(KERN_INFO "nbd: unregistered device at major %d\n", NBD_MAJOR);
+ pr_info("nbd: unregistered device at major %d\n", NBD_MAJOR);
}
module_init(nbd_init);
--
2.6.2
[toc] | [prev] | [next] | [standalone]
| From | Pranay Srivastava <pranjas@gmail.com> |
|---|---|
| Date | 2016-06-06 13:10 +0200 |
| Subject | Re: [PATCH 0/4]nbd: fixes for nbd |
| Message-ID | <rH0zU-47m-25@gated-at.bofh.it> |
| In reply to | #1412350 |
This got rejected by mailing-list[due to HTML content] so resending it again.
On Sat, Jun 4, 2016 at 10:25 AM, Pranay Srivastava <pranjas@gmail.com> wrote:
>
>
> On Thursday, June 2, 2016, Pranay Kr. Srivastava <pranjas@gmail.com> wrote:
>> This patch series fixes the following
>>
>> 1) fix might_sleep warning on socket shutdown:
>> Fix sock_shutdown to avoid calling kernel_sock_shutdown
>> while holding spin_lock.
>>
>> 2) cleanup nbd_set_socket
>> Cleanup nbd_set_socket to use spin_lock instead of
>> irq version and remove the goto statement in favour
>> of a simple if-else statement.
>>
>> 3) fix various coding standard warnings
>> Make shutdown get called in a process context instead, using
>> system_wq.
>>
>> 4) make nbd device wait for its users.
>> When a timeout or error occurs then nbd driver simply kills
>> the block device. Many filesystem(s) example ext2/ext3 don't
>> expect their buffer heads to disappear like that. Fix this
>> by making nbd device wait for its users.
>>
>> Introduced a new field to check if the device is currently
>> in use or not. This helps to check if the kref_put should
>> be done on device release or not.
>>
>> This field needs to be atomic as the release function may
>> be called from NBD_DO_IT as well as from device's release
>> function.
>>
>> 5) use device_attr macros for sysfs attribute
>> use DEVICE_ATTR_RO for sysfs pid attribute.
>>
>> Changelog for v2:
>> 1) fix might_sleep warning on socket shutdown
>> use bool timedout instead of atomic
>>
>> 2) cleanup nbd_set_socket
>> Added this new patch to this series.
>>
>> 3) fix various coding standard warnings
>> No Change.
>>
>> 4) make nbd device wait for its users
>> Earlier version used to do a final kref put when
>> the kref->counter == 2. This required a check of
>> the internal atomic counter of kref which was ugly.
>>
>> v2 of this patch make this more readable and doesn't
>> do manual check of the internal counter used by kref.
>>
>> 5) use device_attr macros for sysfs attribute
>> No Change.
>>
>> Pranay Kr. Srivastava (5):
>> fix might_sleep warning on socket shutdown.
>> cleanup nbd_set_socket
>> fix various coding standard warnings
>> make nbd device wait for its users.
>> use device_attr macros for sysfs attribute
>>
>> drivers/block/nbd.c | 173
>> +++++++++++++++++++++++++++++++++++++---------------
>> 1 file changed, 124 insertions(+), 49 deletions(-)
>>
>> --
>> 2.6.2
>>
>>
> Markus can you please review this series.
>
> --
> ---P.K.S
>
Can anyone kindly review this series?
--
---P.K.S
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web