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>
42 #define PAGE_CACHE_SECTORS (PAGE_CACHE_SIZE >> SECTOR_SHIFT)
43 #define PAGE_CACHE_SECTOR_SHIFT (PAGE_CACHE_SHIFT - SECTOR_SHIFT)
44 #define SECTOR_SIZE (1 << SECTOR_SHIFT)
46 struct block_mount_id
{
47 spinlock_t bm_lock
; /* protects list */
48 struct list_head bm_devlist
; /* holds pnfs_block_dev */
51 struct pnfs_block_dev
{
52 struct list_head bm_node
;
53 struct nfs4_deviceid bm_mdevid
; /* associated devid */
54 struct block_device
*bm_mdev
; /* meta device itself */
59 PNFS_BLOCK_READWRITE_DATA
= 0,
60 PNFS_BLOCK_READ_DATA
= 1,
61 PNFS_BLOCK_INVALID_DATA
= 2, /* mapped, but data is invalid */
62 PNFS_BLOCK_NONE_DATA
= 3 /* unmapped, it's a hole */
65 #define MY_MAX_TAGS (15) /* tag bitnums used must be less than this */
68 sector_t mtt_step_size
; /* Internal sector alignment */
69 struct list_head mtt_stub
; /* Should be a radix tree */
72 struct pnfs_inval_markings
{
74 struct my_tree im_tree
; /* Sectors that need LAYOUTCOMMIT */
75 sector_t im_block_size
; /* Server blocksize in sectors */
76 struct list_head im_extents
; /* Short extents for INVAL->RW conversion */
79 struct pnfs_inval_tracking
{
80 struct list_head it_link
;
85 /* sector_t fields are all in 512-byte sectors */
86 struct pnfs_block_extent
{
87 struct kref be_refcnt
;
88 struct list_head be_node
; /* link into lseg list */
89 struct nfs4_deviceid be_devid
; /* FIXME: could use device cache instead */
90 struct block_device
*be_mdev
;
91 sector_t be_f_offset
; /* the starting offset in the file */
92 sector_t be_length
; /* the size of the extent */
93 sector_t be_v_offset
; /* the starting offset in the volume */
94 enum exstate4 be_state
; /* the state of this extent */
95 struct pnfs_inval_markings
*be_inval
; /* tracks INVAL->RW transition */
98 /* Shortened extent used by LAYOUTCOMMIT */
99 struct pnfs_block_short_extent
{
100 struct list_head bse_node
;
101 struct nfs4_deviceid bse_devid
;
102 struct block_device
*bse_mdev
;
103 sector_t bse_f_offset
; /* the starting offset in the file */
104 sector_t bse_length
; /* the size of the extent */
108 BL_INIT_INVAL_MARKS(struct pnfs_inval_markings
*marks
, sector_t blocksize
)
110 spin_lock_init(&marks
->im_lock
);
111 INIT_LIST_HEAD(&marks
->im_tree
.mtt_stub
);
112 INIT_LIST_HEAD(&marks
->im_extents
);
113 marks
->im_block_size
= blocksize
;
114 marks
->im_tree
.mtt_step_size
= min((sector_t
)PAGE_CACHE_SECTORS
,
119 RW_EXTENT
= 0, /* READWRTE and INVAL */
120 RO_EXTENT
= 1, /* READ and NONE */
124 static inline int bl_choose_list(enum exstate4 state
)
126 if (state
== PNFS_BLOCK_READ_DATA
|| state
== PNFS_BLOCK_NONE_DATA
)
132 struct pnfs_block_layout
{
133 struct pnfs_layout_hdr bl_layout
;
134 struct pnfs_inval_markings bl_inval
; /* tracks INVAL->RW transition */
135 spinlock_t bl_ext_lock
; /* Protects list manipulation */
136 struct list_head bl_extents
[EXTENT_LISTS
]; /* R and RW extents */
137 struct list_head bl_commit
; /* Needs layout commit */
138 struct list_head bl_committing
; /* Layout committing */
139 unsigned int bl_count
; /* entries in bl_commit */
140 sector_t bl_blocksize
; /* Server blocksize in sectors */
143 #define BLK_ID(lo) ((struct block_mount_id *)(NFS_SERVER(lo->plh_inode)->pnfs_ld_data))
145 static inline struct pnfs_block_layout
*
146 BLK_LO2EXT(struct pnfs_layout_hdr
*lo
)
148 return container_of(lo
, struct pnfs_block_layout
, bl_layout
);
151 static inline struct pnfs_block_layout
*
152 BLK_LSEG2EXT(struct pnfs_layout_segment
*lseg
)
154 return BLK_LO2EXT(lseg
->pls_layout
);
158 struct rpc_pipe_msg msg
;
159 wait_queue_head_t
*bl_wq
;
164 u16 totallen
; /* length of entire message, including hdr itself */
167 #define BL_DEVICE_UMOUNT 0x0 /* Umount--delete devices */
168 #define BL_DEVICE_MOUNT 0x1 /* Mount--create devices*/
169 #define BL_DEVICE_REQUEST_INIT 0x0 /* Start request */
170 #define BL_DEVICE_REQUEST_PROC 0x1 /* User level process succeeds */
171 #define BL_DEVICE_REQUEST_ERR 0x2 /* User level process fails */
173 /* blocklayoutdev.c */
174 ssize_t
bl_pipe_downcall(struct file
*, const char __user
*, size_t);
175 void bl_pipe_destroy_msg(struct rpc_pipe_msg
*);
176 void nfs4_blkdev_put(struct block_device
*bdev
);
177 struct pnfs_block_dev
*nfs4_blk_decode_device(struct nfs_server
*server
,
178 struct pnfs_device
*dev
);
179 int nfs4_blk_process_layoutget(struct pnfs_layout_hdr
*lo
,
180 struct nfs4_layoutget_res
*lgr
, gfp_t gfp_flags
);
182 /* blocklayoutdm.c */
183 void bl_free_block_dev(struct pnfs_block_dev
*bdev
);
186 struct pnfs_block_extent
*
187 bl_find_get_extent(struct pnfs_block_layout
*bl
, sector_t isect
,
188 struct pnfs_block_extent
**cow_read
);
189 int bl_mark_sectors_init(struct pnfs_inval_markings
*marks
,
190 sector_t offset
, sector_t length
);
191 void bl_put_extent(struct pnfs_block_extent
*be
);
192 struct pnfs_block_extent
*bl_alloc_extent(void);
193 int bl_is_sector_init(struct pnfs_inval_markings
*marks
, sector_t isect
);
194 int encode_pnfs_block_layoutupdate(struct pnfs_block_layout
*bl
,
195 struct xdr_stream
*xdr
,
196 const struct nfs4_layoutcommit_args
*arg
);
197 void clean_pnfs_block_layoutupdate(struct pnfs_block_layout
*bl
,
198 const struct nfs4_layoutcommit_args
*arg
,
200 int bl_add_merge_extent(struct pnfs_block_layout
*bl
,
201 struct pnfs_block_extent
*new);
202 int bl_mark_for_commit(struct pnfs_block_extent
*be
,
203 sector_t offset
, sector_t length
,
204 struct pnfs_block_short_extent
*new);
205 int bl_push_one_short_extent(struct pnfs_inval_markings
*marks
);
206 struct pnfs_block_short_extent
*
207 bl_pop_one_short_extent(struct pnfs_inval_markings
*marks
);
208 void bl_free_short_extents(struct pnfs_inval_markings
*marks
, int num_to_free
);
210 #endif /* FS_NFS_NFS4BLOCKLAYOUT_H */