blocklayoutdm.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * linux/fs/nfs/blocklayout/blocklayoutdm.c
  3. *
  4. * Module for the NFSv4.1 pNFS block layout driver.
  5. *
  6. * Copyright (c) 2007 The Regents of the University of Michigan.
  7. * All rights reserved.
  8. *
  9. * Fred Isaman <iisaman@umich.edu>
  10. * Andy Adamson <andros@citi.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/genhd.h> /* gendisk - used in a dprintk*/
  33. #include <linux/sched.h>
  34. #include <linux/hash.h>
  35. #include "blocklayout.h"
  36. #define NFSDBG_FACILITY NFSDBG_PNFS_LD
  37. static void dev_remove(dev_t dev)
  38. {
  39. struct rpc_pipe_msg msg;
  40. struct bl_dev_msg bl_umount_request;
  41. struct bl_msg_hdr bl_msg = {
  42. .type = BL_DEVICE_UMOUNT,
  43. .totallen = sizeof(bl_umount_request),
  44. };
  45. uint8_t *dataptr;
  46. DECLARE_WAITQUEUE(wq, current);
  47. dprintk("Entering %s\n", __func__);
  48. memset(&msg, 0, sizeof(msg));
  49. msg.data = kzalloc(1 + sizeof(bl_umount_request), GFP_NOFS);
  50. if (!msg.data)
  51. goto out;
  52. memset(&bl_umount_request, 0, sizeof(bl_umount_request));
  53. bl_umount_request.major = MAJOR(dev);
  54. bl_umount_request.minor = MINOR(dev);
  55. memcpy(msg.data, &bl_msg, sizeof(bl_msg));
  56. dataptr = (uint8_t *) msg.data;
  57. memcpy(&dataptr[sizeof(bl_msg)], &bl_umount_request, sizeof(bl_umount_request));
  58. msg.len = sizeof(bl_msg) + bl_msg.totallen;
  59. add_wait_queue(&bl_wq, &wq);
  60. if (rpc_queue_upcall(bl_device_pipe->d_inode, &msg) < 0) {
  61. remove_wait_queue(&bl_wq, &wq);
  62. goto out;
  63. }
  64. set_current_state(TASK_UNINTERRUPTIBLE);
  65. schedule();
  66. __set_current_state(TASK_RUNNING);
  67. remove_wait_queue(&bl_wq, &wq);
  68. out:
  69. kfree(msg.data);
  70. }
  71. /*
  72. * Release meta device
  73. */
  74. static void nfs4_blk_metadev_release(struct pnfs_block_dev *bdev)
  75. {
  76. int rv;
  77. dprintk("%s Releasing\n", __func__);
  78. rv = nfs4_blkdev_put(bdev->bm_mdev);
  79. if (rv)
  80. printk(KERN_ERR "%s nfs4_blkdev_put returns %d\n",
  81. __func__, rv);
  82. dev_remove(bdev->bm_mdev->bd_dev);
  83. }
  84. void bl_free_block_dev(struct pnfs_block_dev *bdev)
  85. {
  86. if (bdev) {
  87. if (bdev->bm_mdev) {
  88. dprintk("%s Removing DM device: %d:%d\n",
  89. __func__,
  90. MAJOR(bdev->bm_mdev->bd_dev),
  91. MINOR(bdev->bm_mdev->bd_dev));
  92. nfs4_blk_metadev_release(bdev);
  93. }
  94. kfree(bdev);
  95. }
  96. }