1/*
2 * Copyright (C) 2005, 2006
3 * Avishay Traeger (avishay@gmail.com)
4 * Copyright (C) 2008, 2009
5 * Boaz Harrosh <bharrosh@panasas.com>
6 *
7 * Copyrights for code taken from ext2:
8 *     Copyright (C) 1992, 1993, 1994, 1995
9 *     Remy Card (card@masi.ibp.fr)
10 *     Laboratoire MASI - Institut Blaise Pascal
11 *     Universite Pierre et Marie Curie (Paris VI)
12 *     from
13 *     linux/fs/minix/inode.c
14 *     Copyright (C) 1991, 1992  Linus Torvalds
15 *
16 * This file is part of exofs.
17 *
18 * exofs is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation.  Since it is based on ext2, and the only
21 * valid version of GPL for the Linux kernel is version 2, the only valid
22 * version of GPL for exofs is version 2.
23 *
24 * exofs is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27 * GNU General Public License for more details.
28 *
29 * You should have received a copy of the GNU General Public License
30 * along with exofs; if not, write to the Free Software
31 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
32 */
33#ifndef __EXOFS_H__
34#define __EXOFS_H__
35
36#include <linux/fs.h>
37#include <linux/time.h>
38#include <linux/backing-dev.h>
39#include "common.h"
40
41#include "pnfs.h"
42
43#define EXOFS_ERR(fmt, a...) printk(KERN_ERR "exofs: " fmt, ##a)
44
45#ifdef CONFIG_EXOFS_DEBUG
46#define EXOFS_DBGMSG(fmt, a...) \
47	printk(KERN_NOTICE "exofs @%s:%d: " fmt, __func__, __LINE__, ##a)
48#else
49#define EXOFS_DBGMSG(fmt, a...) \
50	do { if (0) printk(fmt, ##a); } while (0)
51#endif
52
53/* u64 has problems with printk this will cast it to unsigned long long */
54#define _LLU(x) (unsigned long long)(x)
55
56struct exofs_layout {
57	osd_id		s_pid;			/* partition ID of file system*/
58
59	/* Our way of looking at the data_map */
60	unsigned stripe_unit;
61	unsigned mirrors_p1;
62
63	unsigned group_width;
64	u64	 group_depth;
65	unsigned group_count;
66
67	enum exofs_inode_layout_gen_functions lay_func;
68
69	unsigned	s_numdevs;		/* Num of devices in array    */
70	struct osd_dev	*s_ods[0];		/* Variable length            */
71};
72
73/*
74 * our extension to the in-memory superblock
75 */
76struct exofs_sb_info {
77	struct exofs_fscb s_fscb;		/* Written often, pre-allocate*/
78	int		s_timeout;		/* timeout for OSD operations */
79	uint64_t	s_nextid;		/* highest object ID used     */
80	uint32_t	s_numfiles;		/* number of files on fs      */
81	spinlock_t	s_next_gen_lock;	/* spinlock for gen # update  */
82	u32		s_next_generation;	/* next gen # to use          */
83	atomic_t	s_curr_pending;		/* number of pending commands */
84	uint8_t		s_cred[OSD_CAP_LEN];	/* credential for the fscb    */
85	struct 		backing_dev_info bdi;	/* register our bdi with VFS  */
86
87	struct pnfs_osd_data_map data_map;
88/*	struct exofs_layout	dir_layout;*/	/* Default dir layout */
89	struct exofs_layout	layout;		/* Default files layout,
90						 * contains the variable osd_dev
91						 * array. Keep last */
92	struct osd_dev	*_min_one_dev[1];	/* Place holder for one dev   */
93};
94
95/*
96 * our extension to the in-memory inode
97 */
98struct exofs_i_info {
99	struct inode   vfs_inode;          /* normal in-memory inode          */
100	wait_queue_head_t i_wq;            /* wait queue for inode            */
101	unsigned long  i_flags;            /* various atomic flags            */
102	uint32_t       i_data[EXOFS_IDATA];/*short symlink names and device #s*/
103	uint32_t       i_dir_start_lookup; /* which page to start lookup      */
104	uint64_t       i_commit_size;      /* the object's written length     */
105	uint8_t        i_cred[OSD_CAP_LEN];/* all-powerful credential         */
106};
107
108static inline osd_id exofs_oi_objno(struct exofs_i_info *oi)
109{
110	return oi->vfs_inode.i_ino + EXOFS_OBJ_OFF;
111}
112
113struct exofs_io_state;
114typedef void (*exofs_io_done_fn)(struct exofs_io_state *or, void *private);
115
116struct exofs_io_state {
117	struct kref		kref;
118
119	void			*private;
120	exofs_io_done_fn	done;
121
122	struct exofs_layout	*layout;
123	struct osd_obj_id	obj;
124	u8			*cred;
125
126	/* Global read/write IO*/
127	loff_t			offset;
128	unsigned long		length;
129	void			*kern_buff;
130
131	struct page		**pages;
132	unsigned		nr_pages;
133	unsigned		pgbase;
134	unsigned		pages_consumed;
135
136	/* Attributes */
137	unsigned		in_attr_len;
138	struct osd_attr 	*in_attr;
139	unsigned		out_attr_len;
140	struct osd_attr 	*out_attr;
141
142	/* Variable array of size numdevs */
143	unsigned numdevs;
144	struct exofs_per_dev_state {
145		struct osd_request *or;
146		struct bio *bio;
147		loff_t offset;
148		unsigned length;
149		unsigned dev;
150	} per_dev[];
151};
152
153static inline unsigned exofs_io_state_size(unsigned numdevs)
154{
155	return sizeof(struct exofs_io_state) +
156		sizeof(struct exofs_per_dev_state) * numdevs;
157}
158
159/*
160 * our inode flags
161 */
162#define OBJ_2BCREATED	0	/* object will be created soon*/
163#define OBJ_CREATED	1	/* object has been created on the osd*/
164
165static inline int obj_2bcreated(struct exofs_i_info *oi)
166{
167	return test_bit(OBJ_2BCREATED, &oi->i_flags);
168}
169
170static inline void set_obj_2bcreated(struct exofs_i_info *oi)
171{
172	set_bit(OBJ_2BCREATED, &oi->i_flags);
173}
174
175static inline int obj_created(struct exofs_i_info *oi)
176{
177	return test_bit(OBJ_CREATED, &oi->i_flags);
178}
179
180static inline void set_obj_created(struct exofs_i_info *oi)
181{
182	set_bit(OBJ_CREATED, &oi->i_flags);
183}
184
185int __exofs_wait_obj_created(struct exofs_i_info *oi);
186static inline int wait_obj_created(struct exofs_i_info *oi)
187{
188	if (likely(obj_created(oi)))
189		return 0;
190
191	return __exofs_wait_obj_created(oi);
192}
193
194/*
195 * get to our inode from the vfs inode
196 */
197static inline struct exofs_i_info *exofs_i(struct inode *inode)
198{
199	return container_of(inode, struct exofs_i_info, vfs_inode);
200}
201
202/*
203 * Given a layout, object_number and stripe_index return the associated global
204 * dev_index
205 */
206unsigned exofs_layout_od_id(struct exofs_layout *layout,
207			    osd_id obj_no, unsigned layout_index);
208/*
209 * Maximum count of links to a file
210 */
211#define EXOFS_LINK_MAX           32000
212
213/*************************
214 * function declarations *
215 *************************/
216
217/* ios.c */
218void exofs_make_credential(u8 cred_a[OSD_CAP_LEN],
219			   const struct osd_obj_id *obj);
220int exofs_read_kern(struct osd_dev *od, u8 *cred, struct osd_obj_id *obj,
221		    u64 offset, void *p, unsigned length);
222
223int  exofs_get_io_state(struct exofs_layout *layout,
224			struct exofs_io_state **ios);
225void exofs_put_io_state(struct exofs_io_state *ios);
226
227int exofs_check_io(struct exofs_io_state *ios, u64 *resid);
228
229int exofs_sbi_create(struct exofs_io_state *ios);
230int exofs_sbi_remove(struct exofs_io_state *ios);
231int exofs_sbi_write(struct exofs_io_state *ios);
232int exofs_sbi_read(struct exofs_io_state *ios);
233
234int extract_attr_from_ios(struct exofs_io_state *ios, struct osd_attr *attr);
235
236int exofs_oi_truncate(struct exofs_i_info *oi, u64 new_len);
237static inline int exofs_oi_write(struct exofs_i_info *oi,
238				 struct exofs_io_state *ios)
239{
240	ios->obj.id = exofs_oi_objno(oi);
241	ios->cred = oi->i_cred;
242	return exofs_sbi_write(ios);
243}
244
245static inline int exofs_oi_read(struct exofs_i_info *oi,
246				struct exofs_io_state *ios)
247{
248	ios->obj.id = exofs_oi_objno(oi);
249	ios->cred = oi->i_cred;
250	return exofs_sbi_read(ios);
251}
252
253/* inode.c               */
254int exofs_setattr(struct dentry *, struct iattr *);
255int exofs_write_begin(struct file *file, struct address_space *mapping,
256		loff_t pos, unsigned len, unsigned flags,
257		struct page **pagep, void **fsdata);
258extern struct inode *exofs_iget(struct super_block *, unsigned long);
259struct inode *exofs_new_inode(struct inode *, int);
260extern int exofs_write_inode(struct inode *, struct writeback_control *wbc);
261extern void exofs_evict_inode(struct inode *);
262
263/* dir.c:                */
264int exofs_add_link(struct dentry *, struct inode *);
265ino_t exofs_inode_by_name(struct inode *, struct dentry *);
266int exofs_delete_entry(struct exofs_dir_entry *, struct page *);
267int exofs_make_empty(struct inode *, struct inode *);
268struct exofs_dir_entry *exofs_find_entry(struct inode *, struct dentry *,
269					 struct page **);
270int exofs_empty_dir(struct inode *);
271struct exofs_dir_entry *exofs_dotdot(struct inode *, struct page **);
272ino_t exofs_parent_ino(struct dentry *child);
273int exofs_set_link(struct inode *, struct exofs_dir_entry *, struct page *,
274		    struct inode *);
275
276/* super.c               */
277int exofs_sync_fs(struct super_block *sb, int wait);
278
279/*********************
280 * operation vectors *
281 *********************/
282/* dir.c:            */
283extern const struct file_operations exofs_dir_operations;
284
285/* file.c            */
286extern const struct inode_operations exofs_file_inode_operations;
287extern const struct file_operations exofs_file_operations;
288
289/* inode.c           */
290extern const struct address_space_operations exofs_aops;
291extern const struct osd_attr g_attr_logical_length;
292
293/* namei.c           */
294extern const struct inode_operations exofs_dir_inode_operations;
295extern const struct inode_operations exofs_special_inode_operations;
296
297/* symlink.c         */
298extern const struct inode_operations exofs_symlink_inode_operations;
299extern const struct inode_operations exofs_fast_symlink_inode_operations;
300
301#endif
302