[PATCH] nbd: show nbd client pid in sysfs
[sfrench/cifs-2.6.git] / drivers / block / nbd.c
index 0a1b1ea36ddcdc3064ba4daa35567a01e0f5b72d..7bf2cfbd6285254009febcf809d4926846ec42e6 100644 (file)
@@ -300,6 +300,15 @@ static struct request *nbd_read_stat(struct nbd_device *lo)
                                lo->disk->disk_name, result);
                goto harderror;
        }
+
+       if (ntohl(reply.magic) != NBD_REPLY_MAGIC) {
+               printk(KERN_ERR "%s: Wrong magic (0x%lx)\n",
+                               lo->disk->disk_name,
+                               (unsigned long)ntohl(reply.magic));
+               result = -EPROTO;
+               goto harderror;
+       }
+
        req = nbd_find_request(lo, reply.handle);
        if (unlikely(IS_ERR(req))) {
                result = PTR_ERR(req);
@@ -312,13 +321,6 @@ static struct request *nbd_read_stat(struct nbd_device *lo)
                goto harderror;
        }
 
-       if (ntohl(reply.magic) != NBD_REPLY_MAGIC) {
-               printk(KERN_ERR "%s: Wrong magic (0x%lx)\n",
-                               lo->disk->disk_name,
-                               (unsigned long)ntohl(reply.magic));
-               result = -EPROTO;
-               goto harderror;
-       }
        if (ntohl(reply.error)) {
                printk(KERN_ERR "%s: Other side returned error (%d)\n",
                                lo->disk->disk_name, ntohl(reply.error));
@@ -339,7 +341,8 @@ static struct request *nbd_read_stat(struct nbd_device *lo)
                                        printk(KERN_ERR "%s: Receive data failed (result %d)\n",
                                                        lo->disk->disk_name,
                                                        result);
-                                       goto harderror;
+                                       req->errors++;
+                                       return req;
                                }
                                dprintk(DBG_RX, "%s: request %p: got %d bytes data\n",
                                        lo->disk->disk_name, req, bvec->bv_len);
@@ -352,14 +355,30 @@ harderror:
        return NULL;
 }
 
+static ssize_t pid_show(struct gendisk *disk, char *page)
+{
+       return sprintf(page, "%ld\n",
+               (long) ((struct nbd_device *)disk->private_data)->pid);
+}
+
+static struct disk_attribute pid_attr = {
+       .attr = { .name = "pid", .mode = S_IRUGO },
+       .show = pid_show,
+};
+
 static void nbd_do_it(struct nbd_device *lo)
 {
        struct request *req;
 
        BUG_ON(lo->magic != LO_MAGIC);
 
+       lo->pid = current->pid;
+       sysfs_create_file(&lo->disk->kobj, &pid_attr.attr);
+
        while ((req = nbd_read_stat(lo)) != NULL)
                nbd_end_request(req);
+
+       sysfs_remove_file(&lo->disk->kobj, &pid_attr.attr);
        return;
 }
 
@@ -404,10 +423,10 @@ static void do_nbd_request(request_queue_t * q)
                struct nbd_device *lo;
 
                blkdev_dequeue_request(req);
-               dprintk(DBG_BLKDEV, "%s: request %p: dequeued (flags=%lx)\n",
-                               req->rq_disk->disk_name, req, req->flags);
+               dprintk(DBG_BLKDEV, "%s: request %p: dequeued (flags=%x)\n",
+                               req->rq_disk->disk_name, req, req->cmd_type);
 
-               if (!(req->flags & REQ_CMD))
+               if (!blk_fs_request(req))
                        goto error_out;
 
                lo = req->rq_disk->private_data;
@@ -486,7 +505,7 @@ static int nbd_ioctl(struct inode *inode, struct file *file,
        switch (cmd) {
        case NBD_DISCONNECT:
                printk(KERN_INFO "%s: NBD_DISCONNECT\n", lo->disk->disk_name);
-               sreq.flags = REQ_SPECIAL;
+               sreq.cmd_type = REQ_TYPE_SPECIAL;
                nbd_cmd(&sreq) = NBD_CMD_DISC;
                /*
                 * Set these to sane values in case server implementation