Jim Rees | 025a70e | 2011-07-30 20:52:43 -0400 | [diff] [blame] | 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 | |
| 33 | #include <linux/genhd.h> /* gendisk - used in a dprintk*/ |
| 34 | #include <linux/sched.h> |
| 35 | #include <linux/hash.h> |
| 36 | |
| 37 | #include "blocklayout.h" |
| 38 | |
| 39 | #define NFSDBG_FACILITY NFSDBG_PNFS_LD |
| 40 | |
Stanislav Kinsbursky | 9e2e74d | 2012-01-10 17:04:24 +0400 | [diff] [blame] | 41 | static void dev_remove(struct net *net, dev_t dev) |
Jim Rees | 025a70e | 2011-07-30 20:52:43 -0400 | [diff] [blame] | 42 | { |
Stanislav Kinsbursky | 5ffaf85 | 2012-03-11 18:20:31 +0400 | [diff] [blame] | 43 | struct bl_pipe_msg bl_pipe_msg; |
| 44 | struct rpc_pipe_msg *msg = &bl_pipe_msg.msg; |
Jim Rees | 025a70e | 2011-07-30 20:52:43 -0400 | [diff] [blame] | 45 | struct bl_dev_msg bl_umount_request; |
| 46 | struct bl_msg_hdr bl_msg = { |
| 47 | .type = BL_DEVICE_UMOUNT, |
| 48 | .totallen = sizeof(bl_umount_request), |
| 49 | }; |
| 50 | uint8_t *dataptr; |
| 51 | DECLARE_WAITQUEUE(wq, current); |
Stanislav Kinsbursky | 9e2e74d | 2012-01-10 17:04:24 +0400 | [diff] [blame] | 52 | struct nfs_net *nn = net_generic(net, nfs_net_id); |
Jim Rees | 025a70e | 2011-07-30 20:52:43 -0400 | [diff] [blame] | 53 | |
| 54 | dprintk("Entering %s\n", __func__); |
| 55 | |
Stanislav Kinsbursky | 5ffaf85 | 2012-03-11 18:20:31 +0400 | [diff] [blame] | 56 | bl_pipe_msg.bl_wq = &nn->bl_wq; |
Dan Carpenter | e138ead | 2012-03-13 20:18:48 +0300 | [diff] [blame] | 57 | memset(msg, 0, sizeof(*msg)); |
Stanislav Kinsbursky | 5ffaf85 | 2012-03-11 18:20:31 +0400 | [diff] [blame] | 58 | msg->data = kzalloc(1 + sizeof(bl_umount_request), GFP_NOFS); |
| 59 | if (!msg->data) |
Jim Rees | 025a70e | 2011-07-30 20:52:43 -0400 | [diff] [blame] | 60 | goto out; |
| 61 | |
| 62 | memset(&bl_umount_request, 0, sizeof(bl_umount_request)); |
| 63 | bl_umount_request.major = MAJOR(dev); |
| 64 | bl_umount_request.minor = MINOR(dev); |
| 65 | |
Stanislav Kinsbursky | 5ffaf85 | 2012-03-11 18:20:31 +0400 | [diff] [blame] | 66 | memcpy(msg->data, &bl_msg, sizeof(bl_msg)); |
| 67 | dataptr = (uint8_t *) msg->data; |
Jim Rees | 025a70e | 2011-07-30 20:52:43 -0400 | [diff] [blame] | 68 | memcpy(&dataptr[sizeof(bl_msg)], &bl_umount_request, sizeof(bl_umount_request)); |
Stanislav Kinsbursky | 5ffaf85 | 2012-03-11 18:20:31 +0400 | [diff] [blame] | 69 | msg->len = sizeof(bl_msg) + bl_msg.totallen; |
Jim Rees | 025a70e | 2011-07-30 20:52:43 -0400 | [diff] [blame] | 70 | |
Stanislav Kinsbursky | 5ffaf85 | 2012-03-11 18:20:31 +0400 | [diff] [blame] | 71 | add_wait_queue(&nn->bl_wq, &wq); |
| 72 | if (rpc_queue_upcall(nn->bl_device_pipe, msg) < 0) { |
| 73 | remove_wait_queue(&nn->bl_wq, &wq); |
Jim Rees | 025a70e | 2011-07-30 20:52:43 -0400 | [diff] [blame] | 74 | goto out; |
| 75 | } |
| 76 | |
| 77 | set_current_state(TASK_UNINTERRUPTIBLE); |
| 78 | schedule(); |
| 79 | __set_current_state(TASK_RUNNING); |
Stanislav Kinsbursky | 5ffaf85 | 2012-03-11 18:20:31 +0400 | [diff] [blame] | 80 | remove_wait_queue(&nn->bl_wq, &wq); |
Jim Rees | 025a70e | 2011-07-30 20:52:43 -0400 | [diff] [blame] | 81 | |
| 82 | out: |
Stanislav Kinsbursky | 5ffaf85 | 2012-03-11 18:20:31 +0400 | [diff] [blame] | 83 | kfree(msg->data); |
Jim Rees | 025a70e | 2011-07-30 20:52:43 -0400 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | /* |
| 87 | * Release meta device |
| 88 | */ |
| 89 | static void nfs4_blk_metadev_release(struct pnfs_block_dev *bdev) |
| 90 | { |
| 91 | int rv; |
| 92 | |
| 93 | dprintk("%s Releasing\n", __func__); |
| 94 | rv = nfs4_blkdev_put(bdev->bm_mdev); |
| 95 | if (rv) |
Weston Andros Adamson | a030889 | 2012-01-26 13:32:23 -0500 | [diff] [blame] | 96 | printk(KERN_ERR "NFS: %s nfs4_blkdev_put returns %d\n", |
Jim Rees | 025a70e | 2011-07-30 20:52:43 -0400 | [diff] [blame] | 97 | __func__, rv); |
| 98 | |
Stanislav Kinsbursky | 9e2e74d | 2012-01-10 17:04:24 +0400 | [diff] [blame] | 99 | dev_remove(bdev->net, bdev->bm_mdev->bd_dev); |
Jim Rees | 025a70e | 2011-07-30 20:52:43 -0400 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | void bl_free_block_dev(struct pnfs_block_dev *bdev) |
| 103 | { |
| 104 | if (bdev) { |
| 105 | if (bdev->bm_mdev) { |
| 106 | dprintk("%s Removing DM device: %d:%d\n", |
| 107 | __func__, |
| 108 | MAJOR(bdev->bm_mdev->bd_dev), |
| 109 | MINOR(bdev->bm_mdev->bd_dev)); |
| 110 | nfs4_blk_metadev_release(bdev); |
| 111 | } |
| 112 | kfree(bdev); |
| 113 | } |
| 114 | } |