Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 1 | /* |
| 2 | * linux/fs/nfs/blocklayout/blocklayout.h |
| 3 | * |
| 4 | * Module for the NFSv4.1 pNFS block 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 | #ifndef FS_NFS_NFS4BLOCKLAYOUT_H |
| 33 | #define FS_NFS_NFS4BLOCKLAYOUT_H |
| 34 | |
| 35 | #include <linux/device-mapper.h> |
| 36 | #include <linux/nfs_fs.h> |
Jim Rees | fe0a9b7 | 2011-07-30 20:52:42 -0400 | [diff] [blame] | 37 | #include <linux/sunrpc/rpc_pipe_fs.h> |
| 38 | |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 39 | #include "../pnfs.h" |
| 40 | |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 41 | struct block_mount_id { |
| 42 | spinlock_t bm_lock; /* protects list */ |
| 43 | struct list_head bm_devlist; /* holds pnfs_block_dev */ |
| 44 | }; |
| 45 | |
Jim Rees | fe0a9b7 | 2011-07-30 20:52:42 -0400 | [diff] [blame] | 46 | struct pnfs_block_dev { |
| 47 | struct list_head bm_node; |
| 48 | struct nfs4_deviceid bm_mdevid; /* associated devid */ |
| 49 | struct block_device *bm_mdev; /* meta device itself */ |
| 50 | }; |
| 51 | |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 52 | enum exstate4 { |
| 53 | PNFS_BLOCK_READWRITE_DATA = 0, |
| 54 | PNFS_BLOCK_READ_DATA = 1, |
| 55 | PNFS_BLOCK_INVALID_DATA = 2, /* mapped, but data is invalid */ |
| 56 | PNFS_BLOCK_NONE_DATA = 3 /* unmapped, it's a hole */ |
| 57 | }; |
| 58 | |
| 59 | struct pnfs_inval_markings { |
| 60 | /* STUB */ |
| 61 | }; |
| 62 | |
| 63 | /* sector_t fields are all in 512-byte sectors */ |
| 64 | struct pnfs_block_extent { |
| 65 | struct kref be_refcnt; |
| 66 | struct list_head be_node; /* link into lseg list */ |
| 67 | struct nfs4_deviceid be_devid; /* FIXME: could use device cache instead */ |
| 68 | struct block_device *be_mdev; |
| 69 | sector_t be_f_offset; /* the starting offset in the file */ |
| 70 | sector_t be_length; /* the size of the extent */ |
| 71 | sector_t be_v_offset; /* the starting offset in the volume */ |
| 72 | enum exstate4 be_state; /* the state of this extent */ |
| 73 | struct pnfs_inval_markings *be_inval; /* tracks INVAL->RW transition */ |
| 74 | }; |
| 75 | |
| 76 | static inline void |
| 77 | BL_INIT_INVAL_MARKS(struct pnfs_inval_markings *marks, sector_t blocksize) |
| 78 | { |
| 79 | /* STUB */ |
| 80 | } |
| 81 | |
| 82 | enum extentclass4 { |
| 83 | RW_EXTENT = 0, /* READWRTE and INVAL */ |
| 84 | RO_EXTENT = 1, /* READ and NONE */ |
| 85 | EXTENT_LISTS = 2, |
| 86 | }; |
| 87 | |
Fred Isaman | 03341d2 | 2011-07-30 20:52:45 -0400 | [diff] [blame] | 88 | static inline int bl_choose_list(enum exstate4 state) |
| 89 | { |
| 90 | if (state == PNFS_BLOCK_READ_DATA || state == PNFS_BLOCK_NONE_DATA) |
| 91 | return RO_EXTENT; |
| 92 | else |
| 93 | return RW_EXTENT; |
| 94 | } |
| 95 | |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 96 | struct pnfs_block_layout { |
| 97 | struct pnfs_layout_hdr bl_layout; |
| 98 | struct pnfs_inval_markings bl_inval; /* tracks INVAL->RW transition */ |
| 99 | spinlock_t bl_ext_lock; /* Protects list manipulation */ |
| 100 | struct list_head bl_extents[EXTENT_LISTS]; /* R and RW extents */ |
| 101 | struct list_head bl_commit; /* Needs layout commit */ |
| 102 | struct list_head bl_committing; /* Layout committing */ |
| 103 | unsigned int bl_count; /* entries in bl_commit */ |
| 104 | sector_t bl_blocksize; /* Server blocksize in sectors */ |
| 105 | }; |
| 106 | |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 107 | #define BLK_ID(lo) ((struct block_mount_id *)(NFS_SERVER(lo->plh_inode)->pnfs_ld_data)) |
| 108 | |
| 109 | static inline struct pnfs_block_layout * |
| 110 | BLK_LO2EXT(struct pnfs_layout_hdr *lo) |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 111 | { |
| 112 | return container_of(lo, struct pnfs_block_layout, bl_layout); |
| 113 | } |
| 114 | |
Fred Isaman | a60d2eb | 2011-07-30 20:52:44 -0400 | [diff] [blame] | 115 | static inline struct pnfs_block_layout * |
| 116 | BLK_LSEG2EXT(struct pnfs_layout_segment *lseg) |
| 117 | { |
| 118 | return BLK_LO2EXT(lseg->pls_layout); |
| 119 | } |
| 120 | |
Jim Rees | fe0a9b7 | 2011-07-30 20:52:42 -0400 | [diff] [blame] | 121 | struct bl_dev_msg { |
| 122 | int status; |
| 123 | uint32_t major, minor; |
| 124 | }; |
| 125 | |
| 126 | struct bl_msg_hdr { |
| 127 | u8 type; |
| 128 | u16 totallen; /* length of entire message, including hdr itself */ |
| 129 | }; |
| 130 | |
| 131 | extern struct dentry *bl_device_pipe; |
| 132 | extern wait_queue_head_t bl_wq; |
| 133 | |
| 134 | #define BL_DEVICE_UMOUNT 0x0 /* Umount--delete devices */ |
| 135 | #define BL_DEVICE_MOUNT 0x1 /* Mount--create devices*/ |
| 136 | #define BL_DEVICE_REQUEST_INIT 0x0 /* Start request */ |
| 137 | #define BL_DEVICE_REQUEST_PROC 0x1 /* User level process succeeds */ |
| 138 | #define BL_DEVICE_REQUEST_ERR 0x2 /* User level process fails */ |
| 139 | |
| 140 | /* blocklayoutdev.c */ |
| 141 | ssize_t bl_pipe_upcall(struct file *, struct rpc_pipe_msg *, |
| 142 | char __user *, size_t); |
| 143 | ssize_t bl_pipe_downcall(struct file *, const char __user *, size_t); |
| 144 | void bl_pipe_destroy_msg(struct rpc_pipe_msg *); |
| 145 | struct block_device *nfs4_blkdev_get(dev_t dev); |
| 146 | int nfs4_blkdev_put(struct block_device *bdev); |
| 147 | struct pnfs_block_dev *nfs4_blk_decode_device(struct nfs_server *server, |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 148 | struct pnfs_device *dev); |
Jim Rees | fe0a9b7 | 2011-07-30 20:52:42 -0400 | [diff] [blame] | 149 | int nfs4_blk_process_layoutget(struct pnfs_layout_hdr *lo, |
| 150 | struct nfs4_layoutget_res *lgr, gfp_t gfp_flags); |
| 151 | |
Jim Rees | 025a70e | 2011-07-30 20:52:43 -0400 | [diff] [blame] | 152 | /* blocklayoutdm.c */ |
| 153 | void bl_free_block_dev(struct pnfs_block_dev *bdev); |
| 154 | |
Fred Isaman | 03341d2 | 2011-07-30 20:52:45 -0400 | [diff] [blame] | 155 | /* extents.c */ |
Fred Isaman | 9e69296 | 2011-07-30 20:52:41 -0400 | [diff] [blame] | 156 | void bl_put_extent(struct pnfs_block_extent *be); |
Fred Isaman | 03341d2 | 2011-07-30 20:52:45 -0400 | [diff] [blame] | 157 | struct pnfs_block_extent *bl_alloc_extent(void); |
| 158 | int bl_add_merge_extent(struct pnfs_block_layout *bl, |
| 159 | struct pnfs_block_extent *new); |
| 160 | |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 161 | #endif /* FS_NFS_NFS4BLOCKLAYOUT_H */ |