2 * linux/fs/nfs/blocklayout/blocklayoutdev.c
4 * Device operations for the pnfs nfs4 file layout driver.
6 * Copyright (c) 2006 The Regents of the University of Michigan.
9 * Andy Adamson <andros@citi.umich.edu>
10 * Fred Isaman <iisaman@umich.edu>
12 * permission is granted to use, copy, create derivative works and
13 * redistribute this software and such derivative works for any purpose,
14 * so long as the name of the university of michigan is not used in
15 * any advertising or publicity pertaining to the use or distribution
16 * of this software without specific, written prior authorization. if
17 * the above copyright notice or any other identification of the
18 * university of michigan is included in any copy of any portion of
19 * this software, then the disclaimer below must also be included.
21 * this software is provided as is, without representation from the
22 * university of michigan as to its fitness for any purpose, and without
23 * warranty by the university of michigan of any kind, either express
24 * or implied, including without limitation the implied warranties of
25 * merchantability and fitness for a particular purpose. the regents
26 * of the university of michigan shall not be liable for any damages,
27 * including special, indirect, incidental, or consequential damages,
28 * with respect to any claim arising out or in connection with the use
29 * of the software, even if it has been or is hereafter advised of the
30 * possibility of such damages.
32 #include <linux/module.h>
33 #include <linux/buffer_head.h> /* __bread */
35 #include <linux/genhd.h>
36 #include <linux/blkdev.h>
37 #include <linux/hash.h>
39 #include "blocklayout.h"
41 #define NFSDBG_FACILITY NFSDBG_PNFS_LD
43 /* Open a block_device by device number. */
44 struct block_device *nfs4_blkdev_get(dev_t dev)
46 struct block_device *bd;
48 dprintk("%s enter\n", __func__);
49 bd = blkdev_get_by_dev(dev, FMODE_READ, NULL);
54 dprintk("%s failed to open device : %ld\n",
55 __func__, PTR_ERR(bd));
60 * Release the block device
62 int nfs4_blkdev_put(struct block_device *bdev)
64 dprintk("%s for device %d:%d\n", __func__, MAJOR(bdev->bd_dev),
66 return blkdev_put(bdev, FMODE_READ);
70 * Shouldn't there be a rpc_generic_upcall() to do this for us?
72 ssize_t bl_pipe_upcall(struct file *filp, struct rpc_pipe_msg *msg,
73 char __user *dst, size_t buflen)
75 char *data = (char *)msg->data + msg->copied;
76 size_t mlen = min(msg->len - msg->copied, buflen);
79 left = copy_to_user(dst, data, mlen);
91 static struct bl_dev_msg bl_mount_reply;
93 ssize_t bl_pipe_downcall(struct file *filp, const char __user *src,
96 if (mlen != sizeof (struct bl_dev_msg))
99 if (copy_from_user(&bl_mount_reply, src, mlen) != 0)
107 void bl_pipe_destroy_msg(struct rpc_pipe_msg *msg)
115 * Decodes pnfs_block_deviceaddr4 which is XDR encoded in dev->dev_addr_buf.
117 struct pnfs_block_dev *
118 nfs4_blk_decode_device(struct nfs_server *server,
119 struct pnfs_device *dev)
121 struct pnfs_block_dev *rv = NULL;
122 struct block_device *bd = NULL;
123 struct rpc_pipe_msg msg;
124 struct bl_msg_hdr bl_msg = {
125 .type = BL_DEVICE_MOUNT,
126 .totallen = dev->mincount,
129 DECLARE_WAITQUEUE(wq, current);
130 struct bl_dev_msg *reply = &bl_mount_reply;
133 dprintk("%s CREATING PIPEFS MESSAGE\n", __func__);
134 dprintk("%s: deviceid: %s, mincount: %d\n", __func__, dev->dev_id.data,
137 memset(&msg, 0, sizeof(msg));
138 msg.data = kzalloc(sizeof(bl_msg) + dev->mincount, GFP_NOFS);
140 rv = ERR_PTR(-ENOMEM);
144 memcpy(msg.data, &bl_msg, sizeof(bl_msg));
145 dataptr = (uint8_t *) msg.data;
147 offset = sizeof(bl_msg);
148 for (i = 0; len > 0; i++) {
149 memcpy(&dataptr[offset], page_address(dev->pages[i]),
150 len < PAGE_CACHE_SIZE ? len : PAGE_CACHE_SIZE);
151 len -= PAGE_CACHE_SIZE;
152 offset += PAGE_CACHE_SIZE;
154 msg.len = sizeof(bl_msg) + dev->mincount;
156 dprintk("%s CALLING USERSPACE DAEMON\n", __func__);
157 add_wait_queue(&bl_wq, &wq);
158 if (rpc_queue_upcall(bl_device_pipe->d_inode, &msg) < 0) {
159 remove_wait_queue(&bl_wq, &wq);
163 set_current_state(TASK_UNINTERRUPTIBLE);
165 __set_current_state(TASK_RUNNING);
166 remove_wait_queue(&bl_wq, &wq);
168 if (reply->status != BL_DEVICE_REQUEST_PROC) {
169 dprintk("%s failed to open device: %d\n",
170 __func__, reply->status);
171 rv = ERR_PTR(-EINVAL);
175 bd = nfs4_blkdev_get(MKDEV(reply->major, reply->minor));
177 dprintk("%s failed to open device : %ld\n",
178 __func__, PTR_ERR(bd));
182 rv = kzalloc(sizeof(*rv), GFP_NOFS);
184 rv = ERR_PTR(-ENOMEM);
189 memcpy(&rv->bm_mdevid, &dev->dev_id, sizeof(struct nfs4_deviceid));
190 dprintk("%s Created device %s with bd_block_size %u\n",
192 bd->bd_disk->disk_name,
201 nfs4_blk_process_layoutget(struct pnfs_layout_hdr *lo,
202 struct nfs4_layoutget_res *lgr, gfp_t gfp_flags)