blocklayoutdev.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. * linux/fs/nfs/blocklayout/blocklayoutdev.c
  3. *
  4. * Device operations for the pnfs nfs4 file layout driver.
  5. *
  6. * Copyright (c) 2006 The Regents of the University of Michigan.
  7. * All rights reserved.
  8. *
  9. * Andy Adamson <andros@citi.umich.edu>
  10. * Fred Isaman <iisaman@umich.edu>
  11. *
  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.
  20. *
  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.
  31. */
  32. #include <linux/module.h>
  33. #include <linux/buffer_head.h> /* __bread */
  34. #include <linux/genhd.h>
  35. #include <linux/blkdev.h>
  36. #include <linux/hash.h>
  37. #include "blocklayout.h"
  38. #define NFSDBG_FACILITY NFSDBG_PNFS_LD
  39. /* Open a block_device by device number. */
  40. struct block_device *nfs4_blkdev_get(dev_t dev)
  41. {
  42. struct block_device *bd;
  43. dprintk("%s enter\n", __func__);
  44. bd = blkdev_get_by_dev(dev, FMODE_READ, NULL);
  45. if (IS_ERR(bd))
  46. goto fail;
  47. return bd;
  48. fail:
  49. dprintk("%s failed to open device : %ld\n",
  50. __func__, PTR_ERR(bd));
  51. return NULL;
  52. }
  53. /*
  54. * Release the block device
  55. */
  56. int nfs4_blkdev_put(struct block_device *bdev)
  57. {
  58. dprintk("%s for device %d:%d\n", __func__, MAJOR(bdev->bd_dev),
  59. MINOR(bdev->bd_dev));
  60. return blkdev_put(bdev, FMODE_READ);
  61. }
  62. /*
  63. * Shouldn't there be a rpc_generic_upcall() to do this for us?
  64. */
  65. ssize_t bl_pipe_upcall(struct file *filp, struct rpc_pipe_msg *msg,
  66. char __user *dst, size_t buflen)
  67. {
  68. char *data = (char *)msg->data + msg->copied;
  69. size_t mlen = min(msg->len - msg->copied, buflen);
  70. unsigned long left;
  71. left = copy_to_user(dst, data, mlen);
  72. if (left == mlen) {
  73. msg->errno = -EFAULT;
  74. return -EFAULT;
  75. }
  76. mlen -= left;
  77. msg->copied += mlen;
  78. msg->errno = 0;
  79. return mlen;
  80. }
  81. static struct bl_dev_msg bl_mount_reply;
  82. ssize_t bl_pipe_downcall(struct file *filp, const char __user *src,
  83. size_t mlen)
  84. {
  85. if (mlen != sizeof (struct bl_dev_msg))
  86. return -EINVAL;
  87. if (copy_from_user(&bl_mount_reply, src, mlen) != 0)
  88. return -EFAULT;
  89. wake_up(&bl_wq);
  90. return mlen;
  91. }
  92. void bl_pipe_destroy_msg(struct rpc_pipe_msg *msg)
  93. {
  94. if (msg->errno >= 0)
  95. return;
  96. wake_up(&bl_wq);
  97. }
  98. /*
  99. * Decodes pnfs_block_deviceaddr4 which is XDR encoded in dev->dev_addr_buf.
  100. */
  101. struct pnfs_block_dev *
  102. nfs4_blk_decode_device(struct nfs_server *server,
  103. struct pnfs_device *dev,
  104. struct list_head *sdlist)
  105. {
  106. struct pnfs_block_dev *rv = NULL;
  107. struct block_device *bd = NULL;
  108. struct rpc_pipe_msg msg;
  109. struct bl_msg_hdr bl_msg = {
  110. .type = BL_DEVICE_MOUNT,
  111. .totallen = dev->mincount,
  112. };
  113. uint8_t *dataptr;
  114. DECLARE_WAITQUEUE(wq, current);
  115. struct bl_dev_msg *reply = &bl_mount_reply;
  116. dprintk("%s CREATING PIPEFS MESSAGE\n", __func__);
  117. dprintk("%s: deviceid: %s, mincount: %d\n", __func__, dev->dev_id.data,
  118. dev->mincount);
  119. memset(&msg, 0, sizeof(msg));
  120. msg.data = kzalloc(sizeof(bl_msg) + dev->mincount, GFP_NOFS);
  121. if (!msg.data) {
  122. rv = ERR_PTR(-ENOMEM);
  123. goto out;
  124. }
  125. memcpy(msg.data, &bl_msg, sizeof(bl_msg));
  126. dataptr = (uint8_t *) msg.data;
  127. memcpy(&dataptr[sizeof(bl_msg)], dev->area, dev->mincount);
  128. msg.len = sizeof(bl_msg) + dev->mincount;
  129. dprintk("%s CALLING USERSPACE DAEMON\n", __func__);
  130. add_wait_queue(&bl_wq, &wq);
  131. if (rpc_queue_upcall(bl_device_pipe->d_inode, &msg) < 0) {
  132. remove_wait_queue(&bl_wq, &wq);
  133. goto out;
  134. }
  135. set_current_state(TASK_UNINTERRUPTIBLE);
  136. schedule();
  137. __set_current_state(TASK_RUNNING);
  138. remove_wait_queue(&bl_wq, &wq);
  139. if (reply->status != BL_DEVICE_REQUEST_PROC) {
  140. dprintk("%s failed to open device: %d\n",
  141. __func__, reply->status);
  142. rv = ERR_PTR(-EINVAL);
  143. goto out;
  144. }
  145. bd = nfs4_blkdev_get(MKDEV(reply->major, reply->minor));
  146. if (IS_ERR(bd)) {
  147. dprintk("%s failed to open device : %ld\n",
  148. __func__, PTR_ERR(bd));
  149. goto out;
  150. }
  151. rv = kzalloc(sizeof(*rv), GFP_NOFS);
  152. if (!rv) {
  153. rv = ERR_PTR(-ENOMEM);
  154. goto out;
  155. }
  156. rv->bm_mdev = bd;
  157. memcpy(&rv->bm_mdevid, &dev->dev_id, sizeof(struct nfs4_deviceid));
  158. dprintk("%s Created device %s with bd_block_size %u\n",
  159. __func__,
  160. bd->bd_disk->disk_name,
  161. bd->bd_block_size);
  162. out:
  163. kfree(msg.data);
  164. return rv;
  165. }
  166. int
  167. nfs4_blk_process_layoutget(struct pnfs_layout_hdr *lo,
  168. struct nfs4_layoutget_res *lgr, gfp_t gfp_flags)
  169. {
  170. /* STUB */
  171. return -EIO;
  172. }