blob: 03350690118e239161fceb18e5939b97d7e062b4 [file] [log] [blame]
Fred Isaman155e7522011-07-30 20:52:39 -04001/*
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 Reesfe0a9b72011-07-30 20:52:42 -040037#include <linux/sunrpc/rpc_pipe_fs.h>
38
Fred Isaman155e7522011-07-30 20:52:39 -040039#include "../pnfs.h"
Stanislav Kinsbursky9e2e74d2012-01-10 17:04:24 +040040#include "../netns.h"
Fred Isaman155e7522011-07-30 20:52:39 -040041
Fred Isamanc1c2a4c2011-07-30 20:52:49 -040042#define PAGE_CACHE_SECTORS (PAGE_CACHE_SIZE >> SECTOR_SHIFT)
43#define PAGE_CACHE_SECTOR_SHIFT (PAGE_CACHE_SHIFT - SECTOR_SHIFT)
44
Fred Isaman2f9fd182011-07-30 20:52:46 -040045struct block_mount_id {
46 spinlock_t bm_lock; /* protects list */
47 struct list_head bm_devlist; /* holds pnfs_block_dev */
48};
49
Jim Reesfe0a9b72011-07-30 20:52:42 -040050struct pnfs_block_dev {
51 struct list_head bm_node;
52 struct nfs4_deviceid bm_mdevid; /* associated devid */
53 struct block_device *bm_mdev; /* meta device itself */
Stanislav Kinsbursky9e2e74d2012-01-10 17:04:24 +040054 struct net *net;
Jim Reesfe0a9b72011-07-30 20:52:42 -040055};
56
Fred Isaman155e7522011-07-30 20:52:39 -040057enum exstate4 {
58 PNFS_BLOCK_READWRITE_DATA = 0,
59 PNFS_BLOCK_READ_DATA = 1,
60 PNFS_BLOCK_INVALID_DATA = 2, /* mapped, but data is invalid */
61 PNFS_BLOCK_NONE_DATA = 3 /* unmapped, it's a hole */
62};
63
Fred Isamanc1c2a4c2011-07-30 20:52:49 -040064#define MY_MAX_TAGS (15) /* tag bitnums used must be less than this */
65
66struct my_tree {
67 sector_t mtt_step_size; /* Internal sector alignment */
68 struct list_head mtt_stub; /* Should be a radix tree */
69};
70
Fred Isaman155e7522011-07-30 20:52:39 -040071struct pnfs_inval_markings {
Fred Isamanc1c2a4c2011-07-30 20:52:49 -040072 spinlock_t im_lock;
73 struct my_tree im_tree; /* Sectors that need LAYOUTCOMMIT */
74 sector_t im_block_size; /* Server blocksize in sectors */
Peng Tao7c5465d2012-01-12 23:18:46 +080075 struct list_head im_extents; /* Short extents for INVAL->RW conversion */
Fred Isamanc1c2a4c2011-07-30 20:52:49 -040076};
77
78struct pnfs_inval_tracking {
79 struct list_head it_link;
80 int it_sector;
81 int it_tags;
Fred Isaman155e7522011-07-30 20:52:39 -040082};
83
84/* sector_t fields are all in 512-byte sectors */
85struct pnfs_block_extent {
86 struct kref be_refcnt;
87 struct list_head be_node; /* link into lseg list */
88 struct nfs4_deviceid be_devid; /* FIXME: could use device cache instead */
89 struct block_device *be_mdev;
90 sector_t be_f_offset; /* the starting offset in the file */
91 sector_t be_length; /* the size of the extent */
92 sector_t be_v_offset; /* the starting offset in the volume */
93 enum exstate4 be_state; /* the state of this extent */
94 struct pnfs_inval_markings *be_inval; /* tracks INVAL->RW transition */
95};
96
Fred Isaman90ace122011-07-30 20:52:51 -040097/* Shortened extent used by LAYOUTCOMMIT */
98struct pnfs_block_short_extent {
99 struct list_head bse_node;
100 struct nfs4_deviceid bse_devid;
101 struct block_device *bse_mdev;
102 sector_t bse_f_offset; /* the starting offset in the file */
103 sector_t bse_length; /* the size of the extent */
104};
105
Fred Isaman155e7522011-07-30 20:52:39 -0400106static inline void
107BL_INIT_INVAL_MARKS(struct pnfs_inval_markings *marks, sector_t blocksize)
108{
Fred Isamanc1c2a4c2011-07-30 20:52:49 -0400109 spin_lock_init(&marks->im_lock);
110 INIT_LIST_HEAD(&marks->im_tree.mtt_stub);
Peng Tao7c5465d2012-01-12 23:18:46 +0800111 INIT_LIST_HEAD(&marks->im_extents);
Fred Isamanc1c2a4c2011-07-30 20:52:49 -0400112 marks->im_block_size = blocksize;
113 marks->im_tree.mtt_step_size = min((sector_t)PAGE_CACHE_SECTORS,
114 blocksize);
Fred Isaman155e7522011-07-30 20:52:39 -0400115}
116
117enum extentclass4 {
118 RW_EXTENT = 0, /* READWRTE and INVAL */
119 RO_EXTENT = 1, /* READ and NONE */
120 EXTENT_LISTS = 2,
121};
122
Fred Isaman03341d22011-07-30 20:52:45 -0400123static inline int bl_choose_list(enum exstate4 state)
124{
125 if (state == PNFS_BLOCK_READ_DATA || state == PNFS_BLOCK_NONE_DATA)
126 return RO_EXTENT;
127 else
128 return RW_EXTENT;
129}
130
Fred Isaman155e7522011-07-30 20:52:39 -0400131struct pnfs_block_layout {
132 struct pnfs_layout_hdr bl_layout;
133 struct pnfs_inval_markings bl_inval; /* tracks INVAL->RW transition */
134 spinlock_t bl_ext_lock; /* Protects list manipulation */
135 struct list_head bl_extents[EXTENT_LISTS]; /* R and RW extents */
136 struct list_head bl_commit; /* Needs layout commit */
137 struct list_head bl_committing; /* Layout committing */
138 unsigned int bl_count; /* entries in bl_commit */
139 sector_t bl_blocksize; /* Server blocksize in sectors */
140};
141
Fred Isaman2f9fd182011-07-30 20:52:46 -0400142#define BLK_ID(lo) ((struct block_mount_id *)(NFS_SERVER(lo->plh_inode)->pnfs_ld_data))
143
144static inline struct pnfs_block_layout *
145BLK_LO2EXT(struct pnfs_layout_hdr *lo)
Fred Isaman155e7522011-07-30 20:52:39 -0400146{
147 return container_of(lo, struct pnfs_block_layout, bl_layout);
148}
149
Fred Isamana60d2eb2011-07-30 20:52:44 -0400150static inline struct pnfs_block_layout *
151BLK_LSEG2EXT(struct pnfs_layout_segment *lseg)
152{
153 return BLK_LO2EXT(lseg->pls_layout);
154}
155
Stanislav Kinsbursky5ffaf852012-03-11 18:20:31 +0400156struct bl_pipe_msg {
157 struct rpc_pipe_msg msg;
158 wait_queue_head_t *bl_wq;
159};
160
Jim Reesfe0a9b72011-07-30 20:52:42 -0400161struct bl_msg_hdr {
162 u8 type;
163 u16 totallen; /* length of entire message, including hdr itself */
164};
165
Jim Reesfe0a9b72011-07-30 20:52:42 -0400166#define BL_DEVICE_UMOUNT 0x0 /* Umount--delete devices */
167#define BL_DEVICE_MOUNT 0x1 /* Mount--create devices*/
168#define BL_DEVICE_REQUEST_INIT 0x0 /* Start request */
169#define BL_DEVICE_REQUEST_PROC 0x1 /* User level process succeeds */
170#define BL_DEVICE_REQUEST_ERR 0x2 /* User level process fails */
171
172/* blocklayoutdev.c */
Jim Reesfe0a9b72011-07-30 20:52:42 -0400173ssize_t bl_pipe_downcall(struct file *, const char __user *, size_t);
174void bl_pipe_destroy_msg(struct rpc_pipe_msg *);
175struct block_device *nfs4_blkdev_get(dev_t dev);
176int nfs4_blkdev_put(struct block_device *bdev);
177struct pnfs_block_dev *nfs4_blk_decode_device(struct nfs_server *server,
Fred Isaman2f9fd182011-07-30 20:52:46 -0400178 struct pnfs_device *dev);
Jim Reesfe0a9b72011-07-30 20:52:42 -0400179int nfs4_blk_process_layoutget(struct pnfs_layout_hdr *lo,
180 struct nfs4_layoutget_res *lgr, gfp_t gfp_flags);
181
Jim Rees025a70e2011-07-30 20:52:43 -0400182/* blocklayoutdm.c */
183void bl_free_block_dev(struct pnfs_block_dev *bdev);
184
Fred Isaman03341d22011-07-30 20:52:45 -0400185/* extents.c */
Fred Isaman6d742ba2011-07-30 20:52:48 -0400186struct pnfs_block_extent *
187bl_find_get_extent(struct pnfs_block_layout *bl, sector_t isect,
188 struct pnfs_block_extent **cow_read);
Fred Isamanc1c2a4c2011-07-30 20:52:49 -0400189int bl_mark_sectors_init(struct pnfs_inval_markings *marks,
Peng Tao60c52e32012-01-12 23:18:40 +0800190 sector_t offset, sector_t length);
Fred Isaman9e692962011-07-30 20:52:41 -0400191void bl_put_extent(struct pnfs_block_extent *be);
Fred Isaman03341d22011-07-30 20:52:45 -0400192struct pnfs_block_extent *bl_alloc_extent(void);
Fred Isamanc1c2a4c2011-07-30 20:52:49 -0400193int bl_is_sector_init(struct pnfs_inval_markings *marks, sector_t isect);
Fred Isaman90ace122011-07-30 20:52:51 -0400194int encode_pnfs_block_layoutupdate(struct pnfs_block_layout *bl,
195 struct xdr_stream *xdr,
196 const struct nfs4_layoutcommit_args *arg);
Fred Isamanb2be7812011-07-30 20:52:52 -0400197void clean_pnfs_block_layoutupdate(struct pnfs_block_layout *bl,
198 const struct nfs4_layoutcommit_args *arg,
199 int status);
Fred Isaman03341d22011-07-30 20:52:45 -0400200int bl_add_merge_extent(struct pnfs_block_layout *bl,
201 struct pnfs_block_extent *new);
Fred Isaman31e63062011-07-30 20:52:55 -0400202int bl_mark_for_commit(struct pnfs_block_extent *be,
Peng Tao7c5465d2012-01-12 23:18:46 +0800203 sector_t offset, sector_t length,
204 struct pnfs_block_short_extent *new);
205int bl_push_one_short_extent(struct pnfs_inval_markings *marks);
206struct pnfs_block_short_extent *
207bl_pop_one_short_extent(struct pnfs_inval_markings *marks);
208void bl_free_short_extents(struct pnfs_inval_markings *marks, int num_to_free);
Fred Isaman03341d22011-07-30 20:52:45 -0400209
Fred Isaman155e7522011-07-30 20:52:39 -0400210#endif /* FS_NFS_NFS4BLOCKLAYOUT_H */