]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - fs/nfs/blocklayout/blocklayout.h
pnfs/blocklayout: move extent processing to blocklayout.c
[karo-tx-linux.git] / fs / nfs / blocklayout / blocklayout.h
1 /*
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>
37 #include <linux/sunrpc/rpc_pipe_fs.h>
38
39 #include "../nfs4_fs.h"
40 #include "../pnfs.h"
41 #include "../netns.h"
42
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)
46
47 struct pnfs_block_dev {
48         struct nfs4_deviceid_node       d_node;
49         struct block_device             *d_bdev;
50 };
51
52 enum exstate4 {
53         PNFS_BLOCK_READWRITE_DATA       = 0,
54         PNFS_BLOCK_READ_DATA            = 1,
55         PNFS_BLOCK_INVALID_DATA         = 2, /* mapped, but data is invalid */
56         PNFS_BLOCK_NONE_DATA            = 3  /* unmapped, it's a hole */
57 };
58
59 /* sector_t fields are all in 512-byte sectors */
60 struct pnfs_block_extent {
61         union {
62                 struct rb_node  be_node;
63                 struct list_head be_list;
64         };
65         struct nfs4_deviceid_node *be_device;
66         sector_t        be_f_offset;    /* the starting offset in the file */
67         sector_t        be_length;      /* the size of the extent */
68         sector_t        be_v_offset;    /* the starting offset in the volume */
69         enum exstate4   be_state;       /* the state of this extent */
70 #define EXTENT_WRITTEN          1
71 #define EXTENT_COMMITTING       2
72         unsigned int    be_tag;
73 };
74
75 /* on the wire size of the extent */
76 #define BL_EXTENT_SIZE  (7 * sizeof(__be32) + NFS4_DEVICEID4_SIZE)
77
78 struct pnfs_block_layout {
79         struct pnfs_layout_hdr  bl_layout;
80         struct rb_root          bl_ext_rw;
81         struct rb_root          bl_ext_ro;
82         spinlock_t              bl_ext_lock;   /* Protects list manipulation */
83 };
84
85 static inline struct pnfs_block_layout *
86 BLK_LO2EXT(struct pnfs_layout_hdr *lo)
87 {
88         return container_of(lo, struct pnfs_block_layout, bl_layout);
89 }
90
91 static inline struct pnfs_block_layout *
92 BLK_LSEG2EXT(struct pnfs_layout_segment *lseg)
93 {
94         return BLK_LO2EXT(lseg->pls_layout);
95 }
96
97 struct bl_pipe_msg {
98         struct rpc_pipe_msg msg;
99         wait_queue_head_t *bl_wq;
100 };
101
102 struct bl_msg_hdr {
103         u8  type;
104         u16 totallen; /* length of entire message, including hdr itself */
105 };
106
107 #define BL_DEVICE_UMOUNT               0x0 /* Umount--delete devices */
108 #define BL_DEVICE_MOUNT                0x1 /* Mount--create devices*/
109 #define BL_DEVICE_REQUEST_INIT         0x0 /* Start request */
110 #define BL_DEVICE_REQUEST_PROC         0x1 /* User level process succeeds */
111 #define BL_DEVICE_REQUEST_ERR          0x2 /* User level process fails */
112
113 /* blocklayoutdev.c */
114 ssize_t bl_pipe_downcall(struct file *, const char __user *, size_t);
115 void bl_pipe_destroy_msg(struct rpc_pipe_msg *);
116
117 struct nfs4_deviceid_node *bl_alloc_deviceid_node(struct nfs_server *server,
118                 struct pnfs_device *pdev, gfp_t gfp_mask);
119 void bl_free_deviceid_node(struct nfs4_deviceid_node *d);
120
121 /* blocklayoutdm.c */
122 void bl_dm_remove(struct net *net, dev_t dev);
123
124 /* extent_tree.c */
125 int ext_tree_insert(struct pnfs_block_layout *bl,
126                 struct pnfs_block_extent *new);
127 int ext_tree_remove(struct pnfs_block_layout *bl, bool rw, sector_t start,
128                 sector_t end);
129 int ext_tree_mark_written(struct pnfs_block_layout *bl, sector_t start,
130                 sector_t len);
131 bool ext_tree_lookup(struct pnfs_block_layout *bl, sector_t isect,
132                 struct pnfs_block_extent *ret, bool rw);
133 int ext_tree_prepare_commit(struct nfs4_layoutcommit_args *arg);
134 void ext_tree_mark_committed(struct nfs4_layoutcommit_args *arg, int status);
135
136 #endif /* FS_NFS_NFS4BLOCKLAYOUT_H */