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 | |
Anna Schumaker | 694e096 | 2013-11-13 12:29:08 -0500 | [diff] [blame] | 39 | #include "../nfs4_fs.h" |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 40 | #include "../pnfs.h" |
Stanislav Kinsbursky | 9e2e74d | 2012-01-10 17:04:24 +0400 | [diff] [blame] | 41 | #include "../netns.h" |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 42 | |
Fred Isaman | c1c2a4c | 2011-07-30 20:52:49 -0400 | [diff] [blame] | 43 | #define PAGE_CACHE_SECTORS (PAGE_CACHE_SIZE >> SECTOR_SHIFT) |
| 44 | #define PAGE_CACHE_SECTOR_SHIFT (PAGE_CACHE_SHIFT - SECTOR_SHIFT) |
Peng Tao | fe6e1e8 | 2012-08-24 00:27:51 +0800 | [diff] [blame] | 45 | #define SECTOR_SIZE (1 << SECTOR_SHIFT) |
Fred Isaman | c1c2a4c | 2011-07-30 20:52:49 -0400 | [diff] [blame] | 46 | |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 47 | struct block_mount_id { |
| 48 | spinlock_t bm_lock; /* protects list */ |
| 49 | struct list_head bm_devlist; /* holds pnfs_block_dev */ |
| 50 | }; |
| 51 | |
Jim Rees | fe0a9b7 | 2011-07-30 20:52:42 -0400 | [diff] [blame] | 52 | struct pnfs_block_dev { |
| 53 | struct list_head bm_node; |
| 54 | struct nfs4_deviceid bm_mdevid; /* associated devid */ |
| 55 | struct block_device *bm_mdev; /* meta device itself */ |
Stanislav Kinsbursky | 9e2e74d | 2012-01-10 17:04:24 +0400 | [diff] [blame] | 56 | struct net *net; |
Jim Rees | fe0a9b7 | 2011-07-30 20:52:42 -0400 | [diff] [blame] | 57 | }; |
| 58 | |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 59 | enum exstate4 { |
| 60 | PNFS_BLOCK_READWRITE_DATA = 0, |
| 61 | PNFS_BLOCK_READ_DATA = 1, |
| 62 | PNFS_BLOCK_INVALID_DATA = 2, /* mapped, but data is invalid */ |
| 63 | PNFS_BLOCK_NONE_DATA = 3 /* unmapped, it's a hole */ |
| 64 | }; |
| 65 | |
Fred Isaman | c1c2a4c | 2011-07-30 20:52:49 -0400 | [diff] [blame] | 66 | #define MY_MAX_TAGS (15) /* tag bitnums used must be less than this */ |
| 67 | |
| 68 | struct my_tree { |
| 69 | sector_t mtt_step_size; /* Internal sector alignment */ |
| 70 | struct list_head mtt_stub; /* Should be a radix tree */ |
| 71 | }; |
| 72 | |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 73 | struct pnfs_inval_markings { |
Fred Isaman | c1c2a4c | 2011-07-30 20:52:49 -0400 | [diff] [blame] | 74 | spinlock_t im_lock; |
| 75 | struct my_tree im_tree; /* Sectors that need LAYOUTCOMMIT */ |
| 76 | sector_t im_block_size; /* Server blocksize in sectors */ |
Peng Tao | 7c5465d | 2012-01-12 23:18:46 +0800 | [diff] [blame] | 77 | struct list_head im_extents; /* Short extents for INVAL->RW conversion */ |
Fred Isaman | c1c2a4c | 2011-07-30 20:52:49 -0400 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | struct pnfs_inval_tracking { |
| 81 | struct list_head it_link; |
| 82 | int it_sector; |
| 83 | int it_tags; |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | /* sector_t fields are all in 512-byte sectors */ |
| 87 | struct pnfs_block_extent { |
| 88 | struct kref be_refcnt; |
| 89 | struct list_head be_node; /* link into lseg list */ |
| 90 | struct nfs4_deviceid be_devid; /* FIXME: could use device cache instead */ |
| 91 | struct block_device *be_mdev; |
| 92 | sector_t be_f_offset; /* the starting offset in the file */ |
| 93 | sector_t be_length; /* the size of the extent */ |
| 94 | sector_t be_v_offset; /* the starting offset in the volume */ |
| 95 | enum exstate4 be_state; /* the state of this extent */ |
| 96 | struct pnfs_inval_markings *be_inval; /* tracks INVAL->RW transition */ |
| 97 | }; |
| 98 | |
Fred Isaman | 90ace12 | 2011-07-30 20:52:51 -0400 | [diff] [blame] | 99 | /* Shortened extent used by LAYOUTCOMMIT */ |
| 100 | struct pnfs_block_short_extent { |
| 101 | struct list_head bse_node; |
| 102 | struct nfs4_deviceid bse_devid; |
| 103 | struct block_device *bse_mdev; |
| 104 | sector_t bse_f_offset; /* the starting offset in the file */ |
| 105 | sector_t bse_length; /* the size of the extent */ |
| 106 | }; |
| 107 | |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 108 | static inline void |
| 109 | BL_INIT_INVAL_MARKS(struct pnfs_inval_markings *marks, sector_t blocksize) |
| 110 | { |
Fred Isaman | c1c2a4c | 2011-07-30 20:52:49 -0400 | [diff] [blame] | 111 | spin_lock_init(&marks->im_lock); |
| 112 | INIT_LIST_HEAD(&marks->im_tree.mtt_stub); |
Peng Tao | 7c5465d | 2012-01-12 23:18:46 +0800 | [diff] [blame] | 113 | INIT_LIST_HEAD(&marks->im_extents); |
Fred Isaman | c1c2a4c | 2011-07-30 20:52:49 -0400 | [diff] [blame] | 114 | marks->im_block_size = blocksize; |
| 115 | marks->im_tree.mtt_step_size = min((sector_t)PAGE_CACHE_SECTORS, |
| 116 | blocksize); |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | enum extentclass4 { |
| 120 | RW_EXTENT = 0, /* READWRTE and INVAL */ |
| 121 | RO_EXTENT = 1, /* READ and NONE */ |
| 122 | EXTENT_LISTS = 2, |
| 123 | }; |
| 124 | |
Fred Isaman | 03341d2 | 2011-07-30 20:52:45 -0400 | [diff] [blame] | 125 | static inline int bl_choose_list(enum exstate4 state) |
| 126 | { |
| 127 | if (state == PNFS_BLOCK_READ_DATA || state == PNFS_BLOCK_NONE_DATA) |
| 128 | return RO_EXTENT; |
| 129 | else |
| 130 | return RW_EXTENT; |
| 131 | } |
| 132 | |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 133 | struct pnfs_block_layout { |
| 134 | struct pnfs_layout_hdr bl_layout; |
| 135 | struct pnfs_inval_markings bl_inval; /* tracks INVAL->RW transition */ |
| 136 | spinlock_t bl_ext_lock; /* Protects list manipulation */ |
| 137 | struct list_head bl_extents[EXTENT_LISTS]; /* R and RW extents */ |
| 138 | struct list_head bl_commit; /* Needs layout commit */ |
| 139 | struct list_head bl_committing; /* Layout committing */ |
| 140 | unsigned int bl_count; /* entries in bl_commit */ |
| 141 | sector_t bl_blocksize; /* Server blocksize in sectors */ |
| 142 | }; |
| 143 | |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 144 | #define BLK_ID(lo) ((struct block_mount_id *)(NFS_SERVER(lo->plh_inode)->pnfs_ld_data)) |
| 145 | |
| 146 | static inline struct pnfs_block_layout * |
| 147 | BLK_LO2EXT(struct pnfs_layout_hdr *lo) |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 148 | { |
| 149 | return container_of(lo, struct pnfs_block_layout, bl_layout); |
| 150 | } |
| 151 | |
Fred Isaman | a60d2eb | 2011-07-30 20:52:44 -0400 | [diff] [blame] | 152 | static inline struct pnfs_block_layout * |
| 153 | BLK_LSEG2EXT(struct pnfs_layout_segment *lseg) |
| 154 | { |
| 155 | return BLK_LO2EXT(lseg->pls_layout); |
| 156 | } |
| 157 | |
Stanislav Kinsbursky | 5ffaf85 | 2012-03-11 18:20:31 +0400 | [diff] [blame] | 158 | struct bl_pipe_msg { |
| 159 | struct rpc_pipe_msg msg; |
| 160 | wait_queue_head_t *bl_wq; |
| 161 | }; |
| 162 | |
Jim Rees | fe0a9b7 | 2011-07-30 20:52:42 -0400 | [diff] [blame] | 163 | struct bl_msg_hdr { |
| 164 | u8 type; |
| 165 | u16 totallen; /* length of entire message, including hdr itself */ |
| 166 | }; |
| 167 | |
Jim Rees | fe0a9b7 | 2011-07-30 20:52:42 -0400 | [diff] [blame] | 168 | #define BL_DEVICE_UMOUNT 0x0 /* Umount--delete devices */ |
| 169 | #define BL_DEVICE_MOUNT 0x1 /* Mount--create devices*/ |
| 170 | #define BL_DEVICE_REQUEST_INIT 0x0 /* Start request */ |
| 171 | #define BL_DEVICE_REQUEST_PROC 0x1 /* User level process succeeds */ |
| 172 | #define BL_DEVICE_REQUEST_ERR 0x2 /* User level process fails */ |
| 173 | |
| 174 | /* blocklayoutdev.c */ |
Jim Rees | fe0a9b7 | 2011-07-30 20:52:42 -0400 | [diff] [blame] | 175 | ssize_t bl_pipe_downcall(struct file *, const char __user *, size_t); |
| 176 | void bl_pipe_destroy_msg(struct rpc_pipe_msg *); |
Al Viro | 4385bab | 2013-05-05 22:11:03 -0400 | [diff] [blame] | 177 | void nfs4_blkdev_put(struct block_device *bdev); |
Jim Rees | fe0a9b7 | 2011-07-30 20:52:42 -0400 | [diff] [blame] | 178 | struct pnfs_block_dev *nfs4_blk_decode_device(struct nfs_server *server, |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 179 | struct pnfs_device *dev); |
Jim Rees | fe0a9b7 | 2011-07-30 20:52:42 -0400 | [diff] [blame] | 180 | int nfs4_blk_process_layoutget(struct pnfs_layout_hdr *lo, |
| 181 | struct nfs4_layoutget_res *lgr, gfp_t gfp_flags); |
| 182 | |
Jim Rees | 025a70e | 2011-07-30 20:52:43 -0400 | [diff] [blame] | 183 | /* blocklayoutdm.c */ |
| 184 | void bl_free_block_dev(struct pnfs_block_dev *bdev); |
| 185 | |
Fred Isaman | 03341d2 | 2011-07-30 20:52:45 -0400 | [diff] [blame] | 186 | /* extents.c */ |
Fred Isaman | 6d742ba | 2011-07-30 20:52:48 -0400 | [diff] [blame] | 187 | struct pnfs_block_extent * |
| 188 | bl_find_get_extent(struct pnfs_block_layout *bl, sector_t isect, |
| 189 | struct pnfs_block_extent **cow_read); |
Fred Isaman | c1c2a4c | 2011-07-30 20:52:49 -0400 | [diff] [blame] | 190 | int bl_mark_sectors_init(struct pnfs_inval_markings *marks, |
Peng Tao | 60c52e3 | 2012-01-12 23:18:40 +0800 | [diff] [blame] | 191 | sector_t offset, sector_t length); |
Fred Isaman | 9e69296 | 2011-07-30 20:52:41 -0400 | [diff] [blame] | 192 | void bl_put_extent(struct pnfs_block_extent *be); |
Fred Isaman | 03341d2 | 2011-07-30 20:52:45 -0400 | [diff] [blame] | 193 | struct pnfs_block_extent *bl_alloc_extent(void); |
Fred Isaman | c1c2a4c | 2011-07-30 20:52:49 -0400 | [diff] [blame] | 194 | int bl_is_sector_init(struct pnfs_inval_markings *marks, sector_t isect); |
Fred Isaman | 90ace12 | 2011-07-30 20:52:51 -0400 | [diff] [blame] | 195 | int encode_pnfs_block_layoutupdate(struct pnfs_block_layout *bl, |
| 196 | struct xdr_stream *xdr, |
| 197 | const struct nfs4_layoutcommit_args *arg); |
Fred Isaman | b2be781 | 2011-07-30 20:52:52 -0400 | [diff] [blame] | 198 | void clean_pnfs_block_layoutupdate(struct pnfs_block_layout *bl, |
| 199 | const struct nfs4_layoutcommit_args *arg, |
| 200 | int status); |
Fred Isaman | 03341d2 | 2011-07-30 20:52:45 -0400 | [diff] [blame] | 201 | int bl_add_merge_extent(struct pnfs_block_layout *bl, |
| 202 | struct pnfs_block_extent *new); |
Fred Isaman | 31e6306 | 2011-07-30 20:52:55 -0400 | [diff] [blame] | 203 | int bl_mark_for_commit(struct pnfs_block_extent *be, |
Peng Tao | 7c5465d | 2012-01-12 23:18:46 +0800 | [diff] [blame] | 204 | sector_t offset, sector_t length, |
| 205 | struct pnfs_block_short_extent *new); |
| 206 | int bl_push_one_short_extent(struct pnfs_inval_markings *marks); |
| 207 | struct pnfs_block_short_extent * |
| 208 | bl_pop_one_short_extent(struct pnfs_inval_markings *marks); |
| 209 | void bl_free_short_extents(struct pnfs_inval_markings *marks, int num_to_free); |
Fred Isaman | 03341d2 | 2011-07-30 20:52:45 -0400 | [diff] [blame] | 210 | |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 211 | #endif /* FS_NFS_NFS4BLOCKLAYOUT_H */ |