2 * linux/fs/nfs/blocklayout/blocklayout.h
4 * Module for the NFSv4.1 pNFS block layout driver.
6 * Copyright (c) 2006 The Regents of the University of Michigan.
9 * Andy Adamson <andros@citi.umich.edu>
10 * Fred Isaman <iisaman@umich.edu>
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.
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.
32 #ifndef FS_NFS_NFS4BLOCKLAYOUT_H
33 #define FS_NFS_NFS4BLOCKLAYOUT_H
35 #include <linux/device-mapper.h>
36 #include <linux/nfs_fs.h>
37 #include <linux/sunrpc/rpc_pipe_fs.h>
39 #include "../nfs4_fs.h"
43 #define PAGE_CACHE_SECTORS (PAGE_CACHE_SIZE >> SECTOR_SHIFT)
44 #define PAGE_CACHE_SECTOR_SHIFT (PAGE_CACHE_SHIFT - SECTOR_SHIFT)
45 #define SECTOR_SIZE (1 << SECTOR_SHIFT)
47 struct pnfs_block_dev
;
49 #define PNFS_BLOCK_MAX_UUIDS 4
50 #define PNFS_BLOCK_MAX_DEVICES 64
53 * Random upper cap for the uuid length to avoid unbounded allocation.
54 * Not actually limited by the protocol.
56 #define PNFS_BLOCK_UUID_LEN 128
59 struct pnfs_block_volume
{
60 enum pnfs_block_volume_type type
;
68 u8 sig
[PNFS_BLOCK_UUID_LEN
];
69 } sigs
[PNFS_BLOCK_MAX_UUIDS
];
78 u32 volumes
[PNFS_BLOCK_MAX_DEVICES
];
83 u32 volumes
[PNFS_BLOCK_MAX_DEVICES
];
88 struct pnfs_block_dev_map
{
93 struct block_device
*bdev
;
96 struct pnfs_block_dev
{
97 struct nfs4_deviceid_node node
;
103 struct pnfs_block_dev
*children
;
106 struct block_device
*bdev
;
109 bool (*map
)(struct pnfs_block_dev
*dev
, u64 offset
,
110 struct pnfs_block_dev_map
*map
);
113 /* sector_t fields are all in 512-byte sectors */
114 struct pnfs_block_extent
{
116 struct rb_node be_node
;
117 struct list_head be_list
;
119 struct nfs4_deviceid_node
*be_device
;
120 sector_t be_f_offset
; /* the starting offset in the file */
121 sector_t be_length
; /* the size of the extent */
122 sector_t be_v_offset
; /* the starting offset in the volume */
123 enum pnfs_block_extent_state be_state
; /* the state of this extent */
124 #define EXTENT_WRITTEN 1
125 #define EXTENT_COMMITTING 2
129 struct pnfs_block_layout
{
130 struct pnfs_layout_hdr bl_layout
;
131 struct rb_root bl_ext_rw
;
132 struct rb_root bl_ext_ro
;
133 spinlock_t bl_ext_lock
; /* Protects list manipulation */
136 static inline struct pnfs_block_layout
*
137 BLK_LO2EXT(struct pnfs_layout_hdr
*lo
)
139 return container_of(lo
, struct pnfs_block_layout
, bl_layout
);
142 static inline struct pnfs_block_layout
*
143 BLK_LSEG2EXT(struct pnfs_layout_segment
*lseg
)
145 return BLK_LO2EXT(lseg
->pls_layout
);
149 struct rpc_pipe_msg msg
;
150 wait_queue_head_t
*bl_wq
;
155 u16 totallen
; /* length of entire message, including hdr itself */
158 #define BL_DEVICE_UMOUNT 0x0 /* Umount--delete devices */
159 #define BL_DEVICE_MOUNT 0x1 /* Mount--create devices*/
160 #define BL_DEVICE_REQUEST_INIT 0x0 /* Start request */
161 #define BL_DEVICE_REQUEST_PROC 0x1 /* User level process succeeds */
162 #define BL_DEVICE_REQUEST_ERR 0x2 /* User level process fails */
165 struct nfs4_deviceid_node
*bl_alloc_deviceid_node(struct nfs_server
*server
,
166 struct pnfs_device
*pdev
, gfp_t gfp_mask
);
167 void bl_free_deviceid_node(struct nfs4_deviceid_node
*d
);
170 int ext_tree_insert(struct pnfs_block_layout
*bl
,
171 struct pnfs_block_extent
*new);
172 int ext_tree_remove(struct pnfs_block_layout
*bl
, bool rw
, sector_t start
,
174 int ext_tree_mark_written(struct pnfs_block_layout
*bl
, sector_t start
,
176 bool ext_tree_lookup(struct pnfs_block_layout
*bl
, sector_t isect
,
177 struct pnfs_block_extent
*ret
, bool rw
);
178 int ext_tree_prepare_commit(struct nfs4_layoutcommit_args
*arg
);
179 void ext_tree_mark_committed(struct nfs4_layoutcommit_args
*arg
, int status
);
182 dev_t
bl_resolve_deviceid(struct nfs_server
*server
,
183 struct pnfs_block_volume
*b
, gfp_t gfp_mask
);
184 int __init
bl_init_pipefs(void);
185 void __exit
bl_cleanup_pipefs(void);
187 #endif /* FS_NFS_NFS4BLOCKLAYOUT_H */