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 | |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 43 | #define PAGE_CACHE_SECTORS (PAGE_SIZE >> SECTOR_SHIFT) |
| 44 | #define PAGE_CACHE_SECTOR_SHIFT (PAGE_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 | |
Christoph Hellwig | 5c83746a | 2014-09-10 17:37:27 -0700 | [diff] [blame] | 47 | struct pnfs_block_dev; |
| 48 | |
Christoph Hellwig | 5c83746a | 2014-09-10 17:37:27 -0700 | [diff] [blame] | 49 | #define PNFS_BLOCK_MAX_UUIDS 4 |
| 50 | #define PNFS_BLOCK_MAX_DEVICES 64 |
| 51 | |
| 52 | /* |
| 53 | * Random upper cap for the uuid length to avoid unbounded allocation. |
| 54 | * Not actually limited by the protocol. |
| 55 | */ |
| 56 | #define PNFS_BLOCK_UUID_LEN 128 |
| 57 | |
Christoph Hellwig | 5c83746a | 2014-09-10 17:37:27 -0700 | [diff] [blame] | 58 | struct pnfs_block_volume { |
| 59 | enum pnfs_block_volume_type type; |
| 60 | union { |
| 61 | struct { |
| 62 | int len; |
| 63 | int nr_sigs; |
| 64 | struct { |
| 65 | u64 offset; |
| 66 | u32 sig_len; |
| 67 | u8 sig[PNFS_BLOCK_UUID_LEN]; |
| 68 | } sigs[PNFS_BLOCK_MAX_UUIDS]; |
| 69 | } simple; |
| 70 | struct { |
| 71 | u64 start; |
| 72 | u64 len; |
| 73 | u32 volume; |
| 74 | } slice; |
| 75 | struct { |
| 76 | u32 volumes_count; |
| 77 | u32 volumes[PNFS_BLOCK_MAX_DEVICES]; |
| 78 | } concat; |
| 79 | struct { |
| 80 | u64 chunk_size; |
| 81 | u32 volumes_count; |
| 82 | u32 volumes[PNFS_BLOCK_MAX_DEVICES]; |
| 83 | } stripe; |
Christoph Hellwig | d9186c0 | 2016-03-04 20:46:15 +0100 | [diff] [blame] | 84 | struct { |
| 85 | enum scsi_code_set code_set; |
| 86 | enum scsi_designator_type designator_type; |
| 87 | int designator_len; |
| 88 | u8 designator[256]; |
| 89 | u64 pr_key; |
| 90 | } scsi; |
Christoph Hellwig | 5c83746a | 2014-09-10 17:37:27 -0700 | [diff] [blame] | 91 | }; |
| 92 | }; |
| 93 | |
| 94 | struct pnfs_block_dev_map { |
| 95 | sector_t start; |
| 96 | sector_t len; |
| 97 | |
| 98 | sector_t disk_offset; |
| 99 | struct block_device *bdev; |
| 100 | }; |
| 101 | |
Jim Rees | fe0a9b7 | 2011-07-30 20:52:42 -0400 | [diff] [blame] | 102 | struct pnfs_block_dev { |
Christoph Hellwig | 5c83746a | 2014-09-10 17:37:27 -0700 | [diff] [blame] | 103 | struct nfs4_deviceid_node node; |
| 104 | |
| 105 | u64 start; |
| 106 | u64 len; |
| 107 | |
| 108 | u32 nr_children; |
| 109 | struct pnfs_block_dev *children; |
| 110 | u64 chunk_size; |
| 111 | |
| 112 | struct block_device *bdev; |
| 113 | u64 disk_offset; |
| 114 | |
Christoph Hellwig | d9186c0 | 2016-03-04 20:46:15 +0100 | [diff] [blame] | 115 | u64 pr_key; |
| 116 | bool pr_registered; |
| 117 | |
Christoph Hellwig | 5c83746a | 2014-09-10 17:37:27 -0700 | [diff] [blame] | 118 | bool (*map)(struct pnfs_block_dev *dev, u64 offset, |
| 119 | struct pnfs_block_dev_map *map); |
Jim Rees | fe0a9b7 | 2011-07-30 20:52:42 -0400 | [diff] [blame] | 120 | }; |
| 121 | |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 122 | /* sector_t fields are all in 512-byte sectors */ |
| 123 | struct pnfs_block_extent { |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 124 | union { |
| 125 | struct rb_node be_node; |
| 126 | struct list_head be_list; |
| 127 | }; |
Christoph Hellwig | 20d655d | 2014-09-02 21:28:00 -0700 | [diff] [blame] | 128 | struct nfs4_deviceid_node *be_device; |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 129 | sector_t be_f_offset; /* the starting offset in the file */ |
| 130 | sector_t be_length; /* the size of the extent */ |
| 131 | sector_t be_v_offset; /* the starting offset in the volume */ |
Christoph Hellwig | 8bb2897 | 2015-08-17 18:41:01 +0200 | [diff] [blame] | 132 | enum pnfs_block_extent_state be_state; /* the state of this extent */ |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 133 | #define EXTENT_WRITTEN 1 |
| 134 | #define EXTENT_COMMITTING 2 |
| 135 | unsigned int be_tag; |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 136 | }; |
| 137 | |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 138 | struct pnfs_block_layout { |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 139 | struct pnfs_layout_hdr bl_layout; |
| 140 | struct rb_root bl_ext_rw; |
| 141 | struct rb_root bl_ext_ro; |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 142 | spinlock_t bl_ext_lock; /* Protects list manipulation */ |
Christoph Hellwig | d9186c0 | 2016-03-04 20:46:15 +0100 | [diff] [blame] | 143 | bool bl_scsi_layout; |
Benjamin Coddington | 41963c1 | 2016-08-22 14:11:16 -0400 | [diff] [blame] | 144 | u64 bl_lwb; |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 145 | }; |
| 146 | |
Fred Isaman | 2f9fd18 | 2011-07-30 20:52:46 -0400 | [diff] [blame] | 147 | static inline struct pnfs_block_layout * |
| 148 | BLK_LO2EXT(struct pnfs_layout_hdr *lo) |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 149 | { |
| 150 | return container_of(lo, struct pnfs_block_layout, bl_layout); |
| 151 | } |
| 152 | |
Fred Isaman | a60d2eb | 2011-07-30 20:52:44 -0400 | [diff] [blame] | 153 | static inline struct pnfs_block_layout * |
| 154 | BLK_LSEG2EXT(struct pnfs_layout_segment *lseg) |
| 155 | { |
| 156 | return BLK_LO2EXT(lseg->pls_layout); |
| 157 | } |
| 158 | |
Stanislav Kinsbursky | 5ffaf85 | 2012-03-11 18:20:31 +0400 | [diff] [blame] | 159 | struct bl_pipe_msg { |
| 160 | struct rpc_pipe_msg msg; |
| 161 | wait_queue_head_t *bl_wq; |
| 162 | }; |
| 163 | |
Jim Rees | fe0a9b7 | 2011-07-30 20:52:42 -0400 | [diff] [blame] | 164 | struct bl_msg_hdr { |
| 165 | u8 type; |
| 166 | u16 totallen; /* length of entire message, including hdr itself */ |
| 167 | }; |
| 168 | |
Jim Rees | fe0a9b7 | 2011-07-30 20:52:42 -0400 | [diff] [blame] | 169 | #define BL_DEVICE_UMOUNT 0x0 /* Umount--delete devices */ |
| 170 | #define BL_DEVICE_MOUNT 0x1 /* Mount--create devices*/ |
| 171 | #define BL_DEVICE_REQUEST_INIT 0x0 /* Start request */ |
| 172 | #define BL_DEVICE_REQUEST_PROC 0x1 /* User level process succeeds */ |
| 173 | #define BL_DEVICE_REQUEST_ERR 0x2 /* User level process fails */ |
| 174 | |
Christoph Hellwig | 5c83746a | 2014-09-10 17:37:27 -0700 | [diff] [blame] | 175 | /* dev.c */ |
| 176 | struct nfs4_deviceid_node *bl_alloc_deviceid_node(struct nfs_server *server, |
| 177 | struct pnfs_device *pdev, gfp_t gfp_mask); |
| 178 | void bl_free_deviceid_node(struct nfs4_deviceid_node *d); |
| 179 | |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 180 | /* extent_tree.c */ |
| 181 | int ext_tree_insert(struct pnfs_block_layout *bl, |
| 182 | struct pnfs_block_extent *new); |
| 183 | int ext_tree_remove(struct pnfs_block_layout *bl, bool rw, sector_t start, |
| 184 | sector_t end); |
| 185 | int ext_tree_mark_written(struct pnfs_block_layout *bl, sector_t start, |
Benjamin Coddington | 41963c1 | 2016-08-22 14:11:16 -0400 | [diff] [blame] | 186 | sector_t len, u64 lwb); |
Christoph Hellwig | 8067253 | 2014-09-10 08:23:34 -0700 | [diff] [blame] | 187 | bool ext_tree_lookup(struct pnfs_block_layout *bl, sector_t isect, |
| 188 | struct pnfs_block_extent *ret, bool rw); |
Christoph Hellwig | 34dc93c | 2014-09-10 17:36:30 -0700 | [diff] [blame] | 189 | int ext_tree_prepare_commit(struct nfs4_layoutcommit_args *arg); |
| 190 | void ext_tree_mark_committed(struct nfs4_layoutcommit_args *arg, int status); |
Fred Isaman | 03341d2 | 2011-07-30 20:52:45 -0400 | [diff] [blame] | 191 | |
Christoph Hellwig | 871760c | 2014-09-10 17:37:26 -0700 | [diff] [blame] | 192 | /* rpc_pipefs.c */ |
Christoph Hellwig | 5c83746a | 2014-09-10 17:37:27 -0700 | [diff] [blame] | 193 | dev_t bl_resolve_deviceid(struct nfs_server *server, |
| 194 | struct pnfs_block_volume *b, gfp_t gfp_mask); |
Christoph Hellwig | 871760c | 2014-09-10 17:37:26 -0700 | [diff] [blame] | 195 | int __init bl_init_pipefs(void); |
Christoph Hellwig | d9186c0 | 2016-03-04 20:46:15 +0100 | [diff] [blame] | 196 | void bl_cleanup_pipefs(void); |
Christoph Hellwig | 871760c | 2014-09-10 17:37:26 -0700 | [diff] [blame] | 197 | |
Fred Isaman | 155e752 | 2011-07-30 20:52:39 -0400 | [diff] [blame] | 198 | #endif /* FS_NFS_NFS4BLOCKLAYOUT_H */ |