blob: fcf47b55b5ce9d3abd86fd7bf451cc74737e4981 [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"
40
Fred Isamanc1c2a4c2011-07-30 20:52:49 -040041#define PAGE_CACHE_SECTORS (PAGE_CACHE_SIZE >> SECTOR_SHIFT)
42#define PAGE_CACHE_SECTOR_SHIFT (PAGE_CACHE_SHIFT - SECTOR_SHIFT)
43
Fred Isaman2f9fd182011-07-30 20:52:46 -040044struct block_mount_id {
45 spinlock_t bm_lock; /* protects list */
46 struct list_head bm_devlist; /* holds pnfs_block_dev */
47};
48
Jim Reesfe0a9b72011-07-30 20:52:42 -040049struct pnfs_block_dev {
50 struct list_head bm_node;
51 struct nfs4_deviceid bm_mdevid; /* associated devid */
52 struct block_device *bm_mdev; /* meta device itself */
53};
54
Fred Isaman155e7522011-07-30 20:52:39 -040055enum exstate4 {
56 PNFS_BLOCK_READWRITE_DATA = 0,
57 PNFS_BLOCK_READ_DATA = 1,
58 PNFS_BLOCK_INVALID_DATA = 2, /* mapped, but data is invalid */
59 PNFS_BLOCK_NONE_DATA = 3 /* unmapped, it's a hole */
60};
61
Fred Isamanc1c2a4c2011-07-30 20:52:49 -040062#define MY_MAX_TAGS (15) /* tag bitnums used must be less than this */
63
64struct my_tree {
65 sector_t mtt_step_size; /* Internal sector alignment */
66 struct list_head mtt_stub; /* Should be a radix tree */
67};
68
Fred Isaman155e7522011-07-30 20:52:39 -040069struct pnfs_inval_markings {
Fred Isamanc1c2a4c2011-07-30 20:52:49 -040070 spinlock_t im_lock;
71 struct my_tree im_tree; /* Sectors that need LAYOUTCOMMIT */
72 sector_t im_block_size; /* Server blocksize in sectors */
73};
74
75struct pnfs_inval_tracking {
76 struct list_head it_link;
77 int it_sector;
78 int it_tags;
Fred Isaman155e7522011-07-30 20:52:39 -040079};
80
81/* sector_t fields are all in 512-byte sectors */
82struct pnfs_block_extent {
83 struct kref be_refcnt;
84 struct list_head be_node; /* link into lseg list */
85 struct nfs4_deviceid be_devid; /* FIXME: could use device cache instead */
86 struct block_device *be_mdev;
87 sector_t be_f_offset; /* the starting offset in the file */
88 sector_t be_length; /* the size of the extent */
89 sector_t be_v_offset; /* the starting offset in the volume */
90 enum exstate4 be_state; /* the state of this extent */
91 struct pnfs_inval_markings *be_inval; /* tracks INVAL->RW transition */
92};
93
94static inline void
95BL_INIT_INVAL_MARKS(struct pnfs_inval_markings *marks, sector_t blocksize)
96{
Fred Isamanc1c2a4c2011-07-30 20:52:49 -040097 spin_lock_init(&marks->im_lock);
98 INIT_LIST_HEAD(&marks->im_tree.mtt_stub);
99 marks->im_block_size = blocksize;
100 marks->im_tree.mtt_step_size = min((sector_t)PAGE_CACHE_SECTORS,
101 blocksize);
Fred Isaman155e7522011-07-30 20:52:39 -0400102}
103
104enum extentclass4 {
105 RW_EXTENT = 0, /* READWRTE and INVAL */
106 RO_EXTENT = 1, /* READ and NONE */
107 EXTENT_LISTS = 2,
108};
109
Fred Isaman03341d22011-07-30 20:52:45 -0400110static inline int bl_choose_list(enum exstate4 state)
111{
112 if (state == PNFS_BLOCK_READ_DATA || state == PNFS_BLOCK_NONE_DATA)
113 return RO_EXTENT;
114 else
115 return RW_EXTENT;
116}
117
Fred Isaman155e7522011-07-30 20:52:39 -0400118struct pnfs_block_layout {
119 struct pnfs_layout_hdr bl_layout;
120 struct pnfs_inval_markings bl_inval; /* tracks INVAL->RW transition */
121 spinlock_t bl_ext_lock; /* Protects list manipulation */
122 struct list_head bl_extents[EXTENT_LISTS]; /* R and RW extents */
123 struct list_head bl_commit; /* Needs layout commit */
124 struct list_head bl_committing; /* Layout committing */
125 unsigned int bl_count; /* entries in bl_commit */
126 sector_t bl_blocksize; /* Server blocksize in sectors */
127};
128
Fred Isaman2f9fd182011-07-30 20:52:46 -0400129#define BLK_ID(lo) ((struct block_mount_id *)(NFS_SERVER(lo->plh_inode)->pnfs_ld_data))
130
131static inline struct pnfs_block_layout *
132BLK_LO2EXT(struct pnfs_layout_hdr *lo)
Fred Isaman155e7522011-07-30 20:52:39 -0400133{
134 return container_of(lo, struct pnfs_block_layout, bl_layout);
135}
136
Fred Isamana60d2eb2011-07-30 20:52:44 -0400137static inline struct pnfs_block_layout *
138BLK_LSEG2EXT(struct pnfs_layout_segment *lseg)
139{
140 return BLK_LO2EXT(lseg->pls_layout);
141}
142
Jim Reesfe0a9b72011-07-30 20:52:42 -0400143struct bl_dev_msg {
144 int status;
145 uint32_t major, minor;
146};
147
148struct bl_msg_hdr {
149 u8 type;
150 u16 totallen; /* length of entire message, including hdr itself */
151};
152
153extern struct dentry *bl_device_pipe;
154extern wait_queue_head_t bl_wq;
155
156#define BL_DEVICE_UMOUNT 0x0 /* Umount--delete devices */
157#define BL_DEVICE_MOUNT 0x1 /* Mount--create devices*/
158#define BL_DEVICE_REQUEST_INIT 0x0 /* Start request */
159#define BL_DEVICE_REQUEST_PROC 0x1 /* User level process succeeds */
160#define BL_DEVICE_REQUEST_ERR 0x2 /* User level process fails */
161
162/* blocklayoutdev.c */
163ssize_t bl_pipe_upcall(struct file *, struct rpc_pipe_msg *,
164 char __user *, size_t);
165ssize_t bl_pipe_downcall(struct file *, const char __user *, size_t);
166void bl_pipe_destroy_msg(struct rpc_pipe_msg *);
167struct block_device *nfs4_blkdev_get(dev_t dev);
168int nfs4_blkdev_put(struct block_device *bdev);
169struct pnfs_block_dev *nfs4_blk_decode_device(struct nfs_server *server,
Fred Isaman2f9fd182011-07-30 20:52:46 -0400170 struct pnfs_device *dev);
Jim Reesfe0a9b72011-07-30 20:52:42 -0400171int nfs4_blk_process_layoutget(struct pnfs_layout_hdr *lo,
172 struct nfs4_layoutget_res *lgr, gfp_t gfp_flags);
173
Jim Rees025a70e2011-07-30 20:52:43 -0400174/* blocklayoutdm.c */
175void bl_free_block_dev(struct pnfs_block_dev *bdev);
176
Fred Isaman03341d22011-07-30 20:52:45 -0400177/* extents.c */
Fred Isaman6d742ba2011-07-30 20:52:48 -0400178struct pnfs_block_extent *
179bl_find_get_extent(struct pnfs_block_layout *bl, sector_t isect,
180 struct pnfs_block_extent **cow_read);
Fred Isamanc1c2a4c2011-07-30 20:52:49 -0400181int bl_mark_sectors_init(struct pnfs_inval_markings *marks,
182 sector_t offset, sector_t length,
183 sector_t **pages);
Fred Isaman9e692962011-07-30 20:52:41 -0400184void bl_put_extent(struct pnfs_block_extent *be);
Fred Isaman03341d22011-07-30 20:52:45 -0400185struct pnfs_block_extent *bl_alloc_extent(void);
Fred Isamanc1c2a4c2011-07-30 20:52:49 -0400186int bl_is_sector_init(struct pnfs_inval_markings *marks, sector_t isect);
Fred Isaman03341d22011-07-30 20:52:45 -0400187int bl_add_merge_extent(struct pnfs_block_layout *bl,
188 struct pnfs_block_extent *new);
189
Fred Isaman155e7522011-07-30 20:52:39 -0400190#endif /* FS_NFS_NFS4BLOCKLAYOUT_H */