blob: 92dca9e90d8dab527d3b5d3b6891981aeb77de11 [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
Anna Schumaker694e0962013-11-13 12:29:08 -050039#include "../nfs4_fs.h"
Fred Isaman155e7522011-07-30 20:52:39 -040040#include "../pnfs.h"
Stanislav Kinsbursky9e2e74d2012-01-10 17:04:24 +040041#include "../netns.h"
Fred Isaman155e7522011-07-30 20:52:39 -040042
Fred Isamanc1c2a4c2011-07-30 20:52:49 -040043#define PAGE_CACHE_SECTORS (PAGE_CACHE_SIZE >> SECTOR_SHIFT)
44#define PAGE_CACHE_SECTOR_SHIFT (PAGE_CACHE_SHIFT - SECTOR_SHIFT)
Peng Taofe6e1e82012-08-24 00:27:51 +080045#define SECTOR_SIZE (1 << SECTOR_SHIFT)
Fred Isamanc1c2a4c2011-07-30 20:52:49 -040046
Christoph Hellwig5c837462014-09-10 17:37:27 -070047struct pnfs_block_dev;
48
49enum pnfs_block_volume_type {
50 PNFS_BLOCK_VOLUME_SIMPLE = 0,
51 PNFS_BLOCK_VOLUME_SLICE = 1,
52 PNFS_BLOCK_VOLUME_CONCAT = 2,
53 PNFS_BLOCK_VOLUME_STRIPE = 3,
54};
55
56#define PNFS_BLOCK_MAX_UUIDS 4
57#define PNFS_BLOCK_MAX_DEVICES 64
58
59/*
60 * Random upper cap for the uuid length to avoid unbounded allocation.
61 * Not actually limited by the protocol.
62 */
63#define PNFS_BLOCK_UUID_LEN 128
64
65
66struct pnfs_block_volume {
67 enum pnfs_block_volume_type type;
68 union {
69 struct {
70 int len;
71 int nr_sigs;
72 struct {
73 u64 offset;
74 u32 sig_len;
75 u8 sig[PNFS_BLOCK_UUID_LEN];
76 } sigs[PNFS_BLOCK_MAX_UUIDS];
77 } simple;
78 struct {
79 u64 start;
80 u64 len;
81 u32 volume;
82 } slice;
83 struct {
84 u32 volumes_count;
85 u32 volumes[PNFS_BLOCK_MAX_DEVICES];
86 } concat;
87 struct {
88 u64 chunk_size;
89 u32 volumes_count;
90 u32 volumes[PNFS_BLOCK_MAX_DEVICES];
91 } stripe;
92 };
93};
94
95struct pnfs_block_dev_map {
96 sector_t start;
97 sector_t len;
98
99 sector_t disk_offset;
100 struct block_device *bdev;
101};
102
Jim Reesfe0a9b72011-07-30 20:52:42 -0400103struct pnfs_block_dev {
Christoph Hellwig5c837462014-09-10 17:37:27 -0700104 struct nfs4_deviceid_node node;
105
106 u64 start;
107 u64 len;
108
109 u32 nr_children;
110 struct pnfs_block_dev *children;
111 u64 chunk_size;
112
113 struct block_device *bdev;
114 u64 disk_offset;
115
116 bool (*map)(struct pnfs_block_dev *dev, u64 offset,
117 struct pnfs_block_dev_map *map);
Jim Reesfe0a9b72011-07-30 20:52:42 -0400118};
119
Fred Isaman155e7522011-07-30 20:52:39 -0400120enum exstate4 {
121 PNFS_BLOCK_READWRITE_DATA = 0,
122 PNFS_BLOCK_READ_DATA = 1,
123 PNFS_BLOCK_INVALID_DATA = 2, /* mapped, but data is invalid */
124 PNFS_BLOCK_NONE_DATA = 3 /* unmapped, it's a hole */
125};
126
Fred Isaman155e7522011-07-30 20:52:39 -0400127/* sector_t fields are all in 512-byte sectors */
128struct pnfs_block_extent {
Christoph Hellwig80672532014-09-10 08:23:34 -0700129 union {
130 struct rb_node be_node;
131 struct list_head be_list;
132 };
Christoph Hellwig20d655d2014-09-02 21:28:00 -0700133 struct nfs4_deviceid_node *be_device;
Fred Isaman155e7522011-07-30 20:52:39 -0400134 sector_t be_f_offset; /* the starting offset in the file */
135 sector_t be_length; /* the size of the extent */
136 sector_t be_v_offset; /* the starting offset in the volume */
137 enum exstate4 be_state; /* the state of this extent */
Christoph Hellwig80672532014-09-10 08:23:34 -0700138#define EXTENT_WRITTEN 1
139#define EXTENT_COMMITTING 2
140 unsigned int be_tag;
Fred Isaman155e7522011-07-30 20:52:39 -0400141};
142
Christoph Hellwig34dc93c2014-09-10 17:36:30 -0700143/* on the wire size of the extent */
144#define BL_EXTENT_SIZE (7 * sizeof(__be32) + NFS4_DEVICEID4_SIZE)
145
Fred Isaman155e7522011-07-30 20:52:39 -0400146struct pnfs_block_layout {
Christoph Hellwig80672532014-09-10 08:23:34 -0700147 struct pnfs_layout_hdr bl_layout;
148 struct rb_root bl_ext_rw;
149 struct rb_root bl_ext_ro;
Fred Isaman155e7522011-07-30 20:52:39 -0400150 spinlock_t bl_ext_lock; /* Protects list manipulation */
Fred Isaman155e7522011-07-30 20:52:39 -0400151};
152
Fred Isaman2f9fd182011-07-30 20:52:46 -0400153static inline struct pnfs_block_layout *
154BLK_LO2EXT(struct pnfs_layout_hdr *lo)
Fred Isaman155e7522011-07-30 20:52:39 -0400155{
156 return container_of(lo, struct pnfs_block_layout, bl_layout);
157}
158
Fred Isamana60d2eb2011-07-30 20:52:44 -0400159static inline struct pnfs_block_layout *
160BLK_LSEG2EXT(struct pnfs_layout_segment *lseg)
161{
162 return BLK_LO2EXT(lseg->pls_layout);
163}
164
Stanislav Kinsbursky5ffaf852012-03-11 18:20:31 +0400165struct bl_pipe_msg {
166 struct rpc_pipe_msg msg;
167 wait_queue_head_t *bl_wq;
168};
169
Jim Reesfe0a9b72011-07-30 20:52:42 -0400170struct bl_msg_hdr {
171 u8 type;
172 u16 totallen; /* length of entire message, including hdr itself */
173};
174
Jim Reesfe0a9b72011-07-30 20:52:42 -0400175#define BL_DEVICE_UMOUNT 0x0 /* Umount--delete devices */
176#define BL_DEVICE_MOUNT 0x1 /* Mount--create devices*/
177#define BL_DEVICE_REQUEST_INIT 0x0 /* Start request */
178#define BL_DEVICE_REQUEST_PROC 0x1 /* User level process succeeds */
179#define BL_DEVICE_REQUEST_ERR 0x2 /* User level process fails */
180
Christoph Hellwig5c837462014-09-10 17:37:27 -0700181/* dev.c */
182struct nfs4_deviceid_node *bl_alloc_deviceid_node(struct nfs_server *server,
183 struct pnfs_device *pdev, gfp_t gfp_mask);
184void bl_free_deviceid_node(struct nfs4_deviceid_node *d);
185
Christoph Hellwig80672532014-09-10 08:23:34 -0700186/* extent_tree.c */
187int ext_tree_insert(struct pnfs_block_layout *bl,
188 struct pnfs_block_extent *new);
189int ext_tree_remove(struct pnfs_block_layout *bl, bool rw, sector_t start,
190 sector_t end);
191int ext_tree_mark_written(struct pnfs_block_layout *bl, sector_t start,
192 sector_t len);
193bool ext_tree_lookup(struct pnfs_block_layout *bl, sector_t isect,
194 struct pnfs_block_extent *ret, bool rw);
Christoph Hellwig34dc93c2014-09-10 17:36:30 -0700195int ext_tree_prepare_commit(struct nfs4_layoutcommit_args *arg);
196void ext_tree_mark_committed(struct nfs4_layoutcommit_args *arg, int status);
Fred Isaman03341d22011-07-30 20:52:45 -0400197
Christoph Hellwig871760c2014-09-10 17:37:26 -0700198/* rpc_pipefs.c */
Christoph Hellwig5c837462014-09-10 17:37:27 -0700199dev_t bl_resolve_deviceid(struct nfs_server *server,
200 struct pnfs_block_volume *b, gfp_t gfp_mask);
Christoph Hellwig871760c2014-09-10 17:37:26 -0700201int __init bl_init_pipefs(void);
202void __exit bl_cleanup_pipefs(void);
203
Fred Isaman155e7522011-07-30 20:52:39 -0400204#endif /* FS_NFS_NFS4BLOCKLAYOUT_H */