Boaz Harrosh | b14f8ab | 2008-10-27 18:27:55 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2005, 2006 |
| 3 | * Avishay Traeger (avishay@gmail.com) (avishay@il.ibm.com) |
| 4 | * Copyright (C) 2005, 2006 |
| 5 | * International Business Machines |
| 6 | * Copyright (C) 2008, 2009 |
| 7 | * Boaz Harrosh <bharrosh@panasas.com> |
| 8 | * |
| 9 | * Copyrights for code taken from ext2: |
| 10 | * Copyright (C) 1992, 1993, 1994, 1995 |
| 11 | * Remy Card (card@masi.ibp.fr) |
| 12 | * Laboratoire MASI - Institut Blaise Pascal |
| 13 | * Universite Pierre et Marie Curie (Paris VI) |
| 14 | * from |
| 15 | * linux/fs/minix/inode.c |
| 16 | * Copyright (C) 1991, 1992 Linus Torvalds |
| 17 | * |
| 18 | * This file is part of exofs. |
| 19 | * |
| 20 | * exofs is free software; you can redistribute it and/or modify |
| 21 | * it under the terms of the GNU General Public License as published by |
| 22 | * the Free Software Foundation. Since it is based on ext2, and the only |
| 23 | * valid version of GPL for the Linux kernel is version 2, the only valid |
| 24 | * version of GPL for exofs is version 2. |
| 25 | * |
| 26 | * exofs is distributed in the hope that it will be useful, |
| 27 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 28 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 29 | * GNU General Public License for more details. |
| 30 | * |
| 31 | * You should have received a copy of the GNU General Public License |
| 32 | * along with exofs; if not, write to the Free Software |
| 33 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 34 | */ |
| 35 | |
| 36 | #include <linux/fs.h> |
| 37 | #include <linux/time.h> |
| 38 | #include "common.h" |
| 39 | |
| 40 | #ifndef __EXOFS_H__ |
| 41 | #define __EXOFS_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 | |
| 56 | /* |
| 57 | * our extension to the in-memory superblock |
| 58 | */ |
| 59 | struct exofs_sb_info { |
| 60 | struct osd_dev *s_dev; /* returned by get_osd_dev */ |
| 61 | osd_id s_pid; /* partition ID of file system*/ |
| 62 | int s_timeout; /* timeout for OSD operations */ |
| 63 | uint64_t s_nextid; /* highest object ID used */ |
| 64 | uint32_t s_numfiles; /* number of files on fs */ |
| 65 | spinlock_t s_next_gen_lock; /* spinlock for gen # update */ |
| 66 | u32 s_next_generation; /* next gen # to use */ |
| 67 | atomic_t s_curr_pending; /* number of pending commands */ |
| 68 | uint8_t s_cred[OSD_CAP_LEN]; /* all-powerful credential */ |
| 69 | }; |
| 70 | |
| 71 | /* |
| 72 | * our extension to the in-memory inode |
| 73 | */ |
| 74 | struct exofs_i_info { |
| 75 | unsigned long i_flags; /* various atomic flags */ |
| 76 | uint32_t i_data[EXOFS_IDATA];/*short symlink names and device #s*/ |
| 77 | uint32_t i_dir_start_lookup; /* which page to start lookup */ |
| 78 | wait_queue_head_t i_wq; /* wait queue for inode */ |
| 79 | uint64_t i_commit_size; /* the object's written length */ |
| 80 | uint8_t i_cred[OSD_CAP_LEN];/* all-powerful credential */ |
| 81 | struct inode vfs_inode; /* normal in-memory inode */ |
| 82 | }; |
| 83 | |
| 84 | /* |
| 85 | * our inode flags |
| 86 | */ |
| 87 | #define OBJ_2BCREATED 0 /* object will be created soon*/ |
| 88 | #define OBJ_CREATED 1 /* object has been created on the osd*/ |
| 89 | |
| 90 | static inline int obj_2bcreated(struct exofs_i_info *oi) |
| 91 | { |
| 92 | return test_bit(OBJ_2BCREATED, &oi->i_flags); |
| 93 | } |
| 94 | |
| 95 | static inline void set_obj_2bcreated(struct exofs_i_info *oi) |
| 96 | { |
| 97 | set_bit(OBJ_2BCREATED, &oi->i_flags); |
| 98 | } |
| 99 | |
| 100 | static inline int obj_created(struct exofs_i_info *oi) |
| 101 | { |
| 102 | return test_bit(OBJ_CREATED, &oi->i_flags); |
| 103 | } |
| 104 | |
| 105 | static inline void set_obj_created(struct exofs_i_info *oi) |
| 106 | { |
| 107 | set_bit(OBJ_CREATED, &oi->i_flags); |
| 108 | } |
| 109 | |
| 110 | int __exofs_wait_obj_created(struct exofs_i_info *oi); |
| 111 | static inline int wait_obj_created(struct exofs_i_info *oi) |
| 112 | { |
| 113 | if (likely(obj_created(oi))) |
| 114 | return 0; |
| 115 | |
| 116 | return __exofs_wait_obj_created(oi); |
| 117 | } |
| 118 | |
| 119 | /* |
| 120 | * get to our inode from the vfs inode |
| 121 | */ |
| 122 | static inline struct exofs_i_info *exofs_i(struct inode *inode) |
| 123 | { |
| 124 | return container_of(inode, struct exofs_i_info, vfs_inode); |
| 125 | } |
| 126 | |
Boaz Harrosh | e6af00f | 2008-10-28 15:38:12 +0200 | [diff] [blame] | 127 | /* |
| 128 | * Maximum count of links to a file |
| 129 | */ |
| 130 | #define EXOFS_LINK_MAX 32000 |
| 131 | |
Boaz Harrosh | e806271 | 2008-10-27 18:37:02 +0200 | [diff] [blame] | 132 | /************************* |
| 133 | * function declarations * |
| 134 | *************************/ |
| 135 | /* inode.c */ |
| 136 | void exofs_truncate(struct inode *inode); |
| 137 | int exofs_setattr(struct dentry *, struct iattr *); |
Boaz Harrosh | beaec07 | 2008-10-27 19:31:34 +0200 | [diff] [blame] | 138 | int exofs_write_begin(struct file *file, struct address_space *mapping, |
| 139 | loff_t pos, unsigned len, unsigned flags, |
| 140 | struct page **pagep, void **fsdata); |
Boaz Harrosh | e6af00f | 2008-10-28 15:38:12 +0200 | [diff] [blame] | 141 | extern struct inode *exofs_iget(struct super_block *, unsigned long); |
| 142 | struct inode *exofs_new_inode(struct inode *, int); |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame^] | 143 | extern int exofs_write_inode(struct inode *, int); |
| 144 | extern void exofs_delete_inode(struct inode *); |
Boaz Harrosh | e6af00f | 2008-10-28 15:38:12 +0200 | [diff] [blame] | 145 | |
| 146 | /* dir.c: */ |
| 147 | int exofs_add_link(struct dentry *, struct inode *); |
| 148 | ino_t exofs_inode_by_name(struct inode *, struct dentry *); |
| 149 | int exofs_delete_entry(struct exofs_dir_entry *, struct page *); |
| 150 | int exofs_make_empty(struct inode *, struct inode *); |
| 151 | struct exofs_dir_entry *exofs_find_entry(struct inode *, struct dentry *, |
| 152 | struct page **); |
| 153 | int exofs_empty_dir(struct inode *); |
| 154 | struct exofs_dir_entry *exofs_dotdot(struct inode *, struct page **); |
| 155 | int exofs_set_link(struct inode *, struct exofs_dir_entry *, struct page *, |
| 156 | struct inode *); |
Boaz Harrosh | e806271 | 2008-10-27 18:37:02 +0200 | [diff] [blame] | 157 | |
| 158 | /********************* |
| 159 | * operation vectors * |
| 160 | *********************/ |
Boaz Harrosh | e6af00f | 2008-10-28 15:38:12 +0200 | [diff] [blame] | 161 | /* dir.c: */ |
| 162 | extern const struct file_operations exofs_dir_operations; |
| 163 | |
Boaz Harrosh | e806271 | 2008-10-27 18:37:02 +0200 | [diff] [blame] | 164 | /* file.c */ |
| 165 | extern const struct inode_operations exofs_file_inode_operations; |
| 166 | extern const struct file_operations exofs_file_operations; |
| 167 | |
Boaz Harrosh | beaec07 | 2008-10-27 19:31:34 +0200 | [diff] [blame] | 168 | /* inode.c */ |
| 169 | extern const struct address_space_operations exofs_aops; |
| 170 | |
Boaz Harrosh | e6af00f | 2008-10-28 15:38:12 +0200 | [diff] [blame] | 171 | /* namei.c */ |
| 172 | extern const struct inode_operations exofs_dir_inode_operations; |
| 173 | extern const struct inode_operations exofs_special_inode_operations; |
| 174 | |
Boaz Harrosh | 982980d | 2008-10-27 19:04:34 +0200 | [diff] [blame] | 175 | /* symlink.c */ |
| 176 | extern const struct inode_operations exofs_symlink_inode_operations; |
| 177 | extern const struct inode_operations exofs_fast_symlink_inode_operations; |
| 178 | |
Boaz Harrosh | b14f8ab | 2008-10-27 18:27:55 +0200 | [diff] [blame] | 179 | #endif |