Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2005, 2006 |
Boaz Harrosh | 27d2e14 | 2009-06-14 17:23:09 +0300 | [diff] [blame] | 3 | * Avishay Traeger (avishay@gmail.com) |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 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 | |
| 34 | #include <linux/string.h> |
| 35 | #include <linux/parser.h> |
| 36 | #include <linux/vfs.h> |
| 37 | #include <linux/random.h> |
Boaz Harrosh | 8cf74b3 | 2009-03-22 12:47:26 +0200 | [diff] [blame] | 38 | #include <linux/exportfs.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 39 | #include <linux/slab.h> |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 40 | |
| 41 | #include "exofs.h" |
| 42 | |
| 43 | /****************************************************************************** |
| 44 | * MOUNT OPTIONS |
| 45 | *****************************************************************************/ |
| 46 | |
| 47 | /* |
| 48 | * struct to hold what we get from mount options |
| 49 | */ |
| 50 | struct exofs_mountopt { |
| 51 | const char *dev_name; |
| 52 | uint64_t pid; |
| 53 | int timeout; |
| 54 | }; |
| 55 | |
| 56 | /* |
| 57 | * exofs-specific mount-time options. |
| 58 | */ |
| 59 | enum { Opt_pid, Opt_to, Opt_mkfs, Opt_format, Opt_err }; |
| 60 | |
| 61 | /* |
| 62 | * Our mount-time options. These should ideally be 64-bit unsigned, but the |
| 63 | * kernel's parsing functions do not currently support that. 32-bit should be |
| 64 | * sufficient for most applications now. |
| 65 | */ |
| 66 | static match_table_t tokens = { |
| 67 | {Opt_pid, "pid=%u"}, |
| 68 | {Opt_to, "to=%u"}, |
| 69 | {Opt_err, NULL} |
| 70 | }; |
| 71 | |
| 72 | /* |
| 73 | * The main option parsing method. Also makes sure that all of the mandatory |
| 74 | * mount options were set. |
| 75 | */ |
| 76 | static int parse_options(char *options, struct exofs_mountopt *opts) |
| 77 | { |
| 78 | char *p; |
| 79 | substring_t args[MAX_OPT_ARGS]; |
| 80 | int option; |
| 81 | bool s_pid = false; |
| 82 | |
| 83 | EXOFS_DBGMSG("parse_options %s\n", options); |
| 84 | /* defaults */ |
| 85 | memset(opts, 0, sizeof(*opts)); |
| 86 | opts->timeout = BLK_DEFAULT_SG_TIMEOUT; |
| 87 | |
| 88 | while ((p = strsep(&options, ",")) != NULL) { |
| 89 | int token; |
| 90 | char str[32]; |
| 91 | |
| 92 | if (!*p) |
| 93 | continue; |
| 94 | |
| 95 | token = match_token(p, tokens, args); |
| 96 | switch (token) { |
| 97 | case Opt_pid: |
| 98 | if (0 == match_strlcpy(str, &args[0], sizeof(str))) |
| 99 | return -EINVAL; |
| 100 | opts->pid = simple_strtoull(str, NULL, 0); |
| 101 | if (opts->pid < EXOFS_MIN_PID) { |
| 102 | EXOFS_ERR("Partition ID must be >= %u", |
| 103 | EXOFS_MIN_PID); |
| 104 | return -EINVAL; |
| 105 | } |
| 106 | s_pid = 1; |
| 107 | break; |
| 108 | case Opt_to: |
| 109 | if (match_int(&args[0], &option)) |
| 110 | return -EINVAL; |
| 111 | if (option <= 0) { |
| 112 | EXOFS_ERR("Timout must be > 0"); |
| 113 | return -EINVAL; |
| 114 | } |
| 115 | opts->timeout = option * HZ; |
| 116 | break; |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | if (!s_pid) { |
| 121 | EXOFS_ERR("Need to specify the following options:\n"); |
| 122 | EXOFS_ERR(" -o pid=pid_no_to_use\n"); |
| 123 | return -EINVAL; |
| 124 | } |
| 125 | |
| 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | /****************************************************************************** |
| 130 | * INODE CACHE |
| 131 | *****************************************************************************/ |
| 132 | |
| 133 | /* |
| 134 | * Our inode cache. Isn't it pretty? |
| 135 | */ |
| 136 | static struct kmem_cache *exofs_inode_cachep; |
| 137 | |
| 138 | /* |
| 139 | * Allocate an inode in the cache |
| 140 | */ |
| 141 | static struct inode *exofs_alloc_inode(struct super_block *sb) |
| 142 | { |
| 143 | struct exofs_i_info *oi; |
| 144 | |
| 145 | oi = kmem_cache_alloc(exofs_inode_cachep, GFP_KERNEL); |
| 146 | if (!oi) |
| 147 | return NULL; |
| 148 | |
| 149 | oi->vfs_inode.i_version = 1; |
| 150 | return &oi->vfs_inode; |
| 151 | } |
| 152 | |
| 153 | /* |
| 154 | * Remove an inode from the cache |
| 155 | */ |
| 156 | static void exofs_destroy_inode(struct inode *inode) |
| 157 | { |
| 158 | kmem_cache_free(exofs_inode_cachep, exofs_i(inode)); |
| 159 | } |
| 160 | |
| 161 | /* |
| 162 | * Initialize the inode |
| 163 | */ |
| 164 | static void exofs_init_once(void *foo) |
| 165 | { |
| 166 | struct exofs_i_info *oi = foo; |
| 167 | |
| 168 | inode_init_once(&oi->vfs_inode); |
| 169 | } |
| 170 | |
| 171 | /* |
| 172 | * Create and initialize the inode cache |
| 173 | */ |
| 174 | static int init_inodecache(void) |
| 175 | { |
| 176 | exofs_inode_cachep = kmem_cache_create("exofs_inode_cache", |
| 177 | sizeof(struct exofs_i_info), 0, |
| 178 | SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD, |
| 179 | exofs_init_once); |
| 180 | if (exofs_inode_cachep == NULL) |
| 181 | return -ENOMEM; |
| 182 | return 0; |
| 183 | } |
| 184 | |
| 185 | /* |
| 186 | * Destroy the inode cache |
| 187 | */ |
| 188 | static void destroy_inodecache(void) |
| 189 | { |
| 190 | kmem_cache_destroy(exofs_inode_cachep); |
| 191 | } |
| 192 | |
| 193 | /****************************************************************************** |
| 194 | * SUPERBLOCK FUNCTIONS |
| 195 | *****************************************************************************/ |
| 196 | static const struct super_operations exofs_sops; |
Boaz Harrosh | 8cf74b3 | 2009-03-22 12:47:26 +0200 | [diff] [blame] | 197 | static const struct export_operations exofs_export_ops; |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 198 | |
| 199 | /* |
| 200 | * Write the superblock to the OSD |
| 201 | */ |
Boaz Harrosh | baaf94c | 2009-06-14 16:52:10 +0300 | [diff] [blame] | 202 | int exofs_sync_fs(struct super_block *sb, int wait) |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 203 | { |
| 204 | struct exofs_sb_info *sbi; |
| 205 | struct exofs_fscb *fscb; |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 206 | struct exofs_io_state *ios; |
Christoph Hellwig | 80e09fb | 2009-06-08 10:03:58 +0200 | [diff] [blame] | 207 | int ret = -ENOMEM; |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 208 | |
Christoph Hellwig | ebc1ac1 | 2009-05-11 23:35:03 +0200 | [diff] [blame] | 209 | lock_super(sb); |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 210 | sbi = sb->s_fs_info; |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 211 | fscb = &sbi->s_fscb; |
| 212 | |
Boaz Harrosh | 45d3abc | 2010-01-28 11:46:16 +0200 | [diff] [blame] | 213 | ret = exofs_get_io_state(&sbi->layout, &ios); |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 214 | if (ret) |
| 215 | goto out; |
| 216 | |
Boaz Harrosh | 04dc1e8 | 2009-11-16 16:03:05 +0200 | [diff] [blame] | 217 | /* Note: We only write the changing part of the fscb. .i.e upto the |
| 218 | * the fscb->s_dev_table_oid member. There is no read-modify-write |
| 219 | * here. |
| 220 | */ |
| 221 | ios->length = offsetof(struct exofs_fscb, s_dev_table_oid); |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 222 | memset(fscb, 0, ios->length); |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 223 | fscb->s_nextid = cpu_to_le64(sbi->s_nextid); |
| 224 | fscb->s_numfiles = cpu_to_le32(sbi->s_numfiles); |
| 225 | fscb->s_magic = cpu_to_le16(sb->s_magic); |
| 226 | fscb->s_newfs = 0; |
Boaz Harrosh | 04dc1e8 | 2009-11-16 16:03:05 +0200 | [diff] [blame] | 227 | fscb->s_version = EXOFS_FSCB_VER; |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 228 | |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 229 | ios->obj.id = EXOFS_SUPER_ID; |
| 230 | ios->offset = 0; |
| 231 | ios->kern_buff = fscb; |
| 232 | ios->cred = sbi->s_cred; |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 233 | |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 234 | ret = exofs_sbi_write(ios); |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 235 | if (unlikely(ret)) { |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 236 | EXOFS_ERR("%s: exofs_sbi_write failed.\n", __func__); |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 237 | goto out; |
| 238 | } |
| 239 | sb->s_dirt = 0; |
| 240 | |
| 241 | out: |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 242 | EXOFS_DBGMSG("s_nextid=0x%llx ret=%d\n", _LLU(sbi->s_nextid), ret); |
| 243 | exofs_put_io_state(ios); |
Christoph Hellwig | ebc1ac1 | 2009-05-11 23:35:03 +0200 | [diff] [blame] | 244 | unlock_super(sb); |
Christoph Hellwig | 80e09fb | 2009-06-08 10:03:58 +0200 | [diff] [blame] | 245 | return ret; |
| 246 | } |
| 247 | |
| 248 | static void exofs_write_super(struct super_block *sb) |
| 249 | { |
| 250 | if (!(sb->s_flags & MS_RDONLY)) |
| 251 | exofs_sync_fs(sb, 1); |
| 252 | else |
| 253 | sb->s_dirt = 0; |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 254 | } |
| 255 | |
Boaz Harrosh | 19fe294 | 2009-09-03 20:38:02 +0300 | [diff] [blame] | 256 | static void _exofs_print_device(const char *msg, const char *dev_path, |
| 257 | struct osd_dev *od, u64 pid) |
| 258 | { |
| 259 | const struct osd_dev_info *odi = osduld_device_info(od); |
| 260 | |
| 261 | printk(KERN_NOTICE "exofs: %s %s osd_name-%s pid-0x%llx\n", |
| 262 | msg, dev_path ?: "", odi->osdname, _LLU(pid)); |
| 263 | } |
| 264 | |
Boaz Harrosh | 04dc1e8 | 2009-11-16 16:03:05 +0200 | [diff] [blame] | 265 | void exofs_free_sbi(struct exofs_sb_info *sbi) |
| 266 | { |
Boaz Harrosh | 45d3abc | 2010-01-28 11:46:16 +0200 | [diff] [blame] | 267 | while (sbi->layout.s_numdevs) { |
| 268 | int i = --sbi->layout.s_numdevs; |
| 269 | struct osd_dev *od = sbi->layout.s_ods[i]; |
Boaz Harrosh | 04dc1e8 | 2009-11-16 16:03:05 +0200 | [diff] [blame] | 270 | |
| 271 | if (od) { |
Boaz Harrosh | 45d3abc | 2010-01-28 11:46:16 +0200 | [diff] [blame] | 272 | sbi->layout.s_ods[i] = NULL; |
Boaz Harrosh | 04dc1e8 | 2009-11-16 16:03:05 +0200 | [diff] [blame] | 273 | osduld_put_device(od); |
| 274 | } |
| 275 | } |
| 276 | kfree(sbi); |
| 277 | } |
| 278 | |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 279 | /* |
| 280 | * This function is called when the vfs is freeing the superblock. We just |
| 281 | * need to free our own part. |
| 282 | */ |
| 283 | static void exofs_put_super(struct super_block *sb) |
| 284 | { |
| 285 | int num_pend; |
| 286 | struct exofs_sb_info *sbi = sb->s_fs_info; |
| 287 | |
Christoph Hellwig | 8c85e12 | 2009-04-28 18:00:26 +0200 | [diff] [blame] | 288 | if (sb->s_dirt) |
| 289 | exofs_write_super(sb); |
| 290 | |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 291 | /* make sure there are no pending commands */ |
| 292 | for (num_pend = atomic_read(&sbi->s_curr_pending); num_pend > 0; |
| 293 | num_pend = atomic_read(&sbi->s_curr_pending)) { |
| 294 | wait_queue_head_t wq; |
| 295 | init_waitqueue_head(&wq); |
| 296 | wait_event_timeout(wq, |
| 297 | (atomic_read(&sbi->s_curr_pending) == 0), |
| 298 | msecs_to_jiffies(100)); |
| 299 | } |
| 300 | |
Boaz Harrosh | 45d3abc | 2010-01-28 11:46:16 +0200 | [diff] [blame] | 301 | _exofs_print_device("Unmounting", NULL, sbi->layout.s_ods[0], |
| 302 | sbi->layout.s_pid); |
Boaz Harrosh | 04dc1e8 | 2009-11-16 16:03:05 +0200 | [diff] [blame] | 303 | |
Jens Axboe | b3d0ab7 | 2010-04-22 12:26:04 +0200 | [diff] [blame] | 304 | bdi_destroy(&sbi->bdi); |
Boaz Harrosh | 04dc1e8 | 2009-11-16 16:03:05 +0200 | [diff] [blame] | 305 | exofs_free_sbi(sbi); |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 306 | sb->s_fs_info = NULL; |
| 307 | } |
| 308 | |
Boaz Harrosh | 04dc1e8 | 2009-11-16 16:03:05 +0200 | [diff] [blame] | 309 | static int _read_and_match_data_map(struct exofs_sb_info *sbi, unsigned numdevs, |
| 310 | struct exofs_device_table *dt) |
| 311 | { |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 312 | u64 stripe_length; |
| 313 | |
Boaz Harrosh | 04dc1e8 | 2009-11-16 16:03:05 +0200 | [diff] [blame] | 314 | sbi->data_map.odm_num_comps = |
| 315 | le32_to_cpu(dt->dt_data_map.cb_num_comps); |
| 316 | sbi->data_map.odm_stripe_unit = |
| 317 | le64_to_cpu(dt->dt_data_map.cb_stripe_unit); |
| 318 | sbi->data_map.odm_group_width = |
| 319 | le32_to_cpu(dt->dt_data_map.cb_group_width); |
| 320 | sbi->data_map.odm_group_depth = |
| 321 | le32_to_cpu(dt->dt_data_map.cb_group_depth); |
| 322 | sbi->data_map.odm_mirror_cnt = |
| 323 | le32_to_cpu(dt->dt_data_map.cb_mirror_cnt); |
| 324 | sbi->data_map.odm_raid_algorithm = |
| 325 | le32_to_cpu(dt->dt_data_map.cb_raid_algorithm); |
| 326 | |
Boaz Harrosh | 50a76fd | 2010-02-11 13:01:39 +0200 | [diff] [blame] | 327 | /* FIXME: Only raid0 for now. if not so, do not mount */ |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 328 | if (sbi->data_map.odm_num_comps != numdevs) { |
| 329 | EXOFS_ERR("odm_num_comps(%u) != numdevs(%u)\n", |
| 330 | sbi->data_map.odm_num_comps, numdevs); |
| 331 | return -EINVAL; |
| 332 | } |
| 333 | if (sbi->data_map.odm_raid_algorithm != PNFS_OSD_RAID_0) { |
| 334 | EXOFS_ERR("Only RAID_0 for now\n"); |
| 335 | return -EINVAL; |
| 336 | } |
| 337 | if (0 != (numdevs % (sbi->data_map.odm_mirror_cnt + 1))) { |
| 338 | EXOFS_ERR("Data Map wrong, numdevs=%d mirrors=%d\n", |
| 339 | numdevs, sbi->data_map.odm_mirror_cnt); |
| 340 | return -EINVAL; |
| 341 | } |
| 342 | |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 343 | if (0 != (sbi->data_map.odm_stripe_unit & ~PAGE_MASK)) { |
| 344 | EXOFS_ERR("Stripe Unit(0x%llx)" |
| 345 | " must be Multples of PAGE_SIZE(0x%lx)\n", |
| 346 | _LLU(sbi->data_map.odm_stripe_unit), PAGE_SIZE); |
| 347 | return -EINVAL; |
| 348 | } |
| 349 | |
| 350 | sbi->layout.stripe_unit = sbi->data_map.odm_stripe_unit; |
| 351 | sbi->layout.mirrors_p1 = sbi->data_map.odm_mirror_cnt + 1; |
Boaz Harrosh | 50a76fd | 2010-02-11 13:01:39 +0200 | [diff] [blame] | 352 | |
| 353 | if (sbi->data_map.odm_group_width) { |
| 354 | sbi->layout.group_width = sbi->data_map.odm_group_width; |
| 355 | sbi->layout.group_depth = sbi->data_map.odm_group_depth; |
| 356 | if (!sbi->layout.group_depth) { |
| 357 | EXOFS_ERR("group_depth == 0 && group_width != 0\n"); |
| 358 | return -EINVAL; |
| 359 | } |
| 360 | sbi->layout.group_count = sbi->data_map.odm_num_comps / |
| 361 | sbi->layout.mirrors_p1 / |
| 362 | sbi->data_map.odm_group_width; |
| 363 | } else { |
| 364 | if (sbi->data_map.odm_group_depth) { |
| 365 | printk(KERN_NOTICE "Warning: group_depth ignored " |
| 366 | "group_width == 0 && group_depth == %d\n", |
| 367 | sbi->data_map.odm_group_depth); |
| 368 | sbi->data_map.odm_group_depth = 0; |
| 369 | } |
| 370 | sbi->layout.group_width = sbi->data_map.odm_num_comps / |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 371 | sbi->layout.mirrors_p1; |
Boaz Harrosh | 50a76fd | 2010-02-11 13:01:39 +0200 | [diff] [blame] | 372 | sbi->layout.group_depth = -1; |
| 373 | sbi->layout.group_count = 1; |
| 374 | } |
| 375 | |
| 376 | stripe_length = (u64)sbi->layout.group_width * sbi->layout.stripe_unit; |
| 377 | if (stripe_length >= (1ULL << 32)) { |
| 378 | EXOFS_ERR("Total Stripe length(0x%llx)" |
| 379 | " >= 32bit is not supported\n", _LLU(stripe_length)); |
| 380 | return -EINVAL; |
| 381 | } |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 382 | |
| 383 | return 0; |
Boaz Harrosh | 04dc1e8 | 2009-11-16 16:03:05 +0200 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | /* @odi is valid only as long as @fscb_dev is valid */ |
| 387 | static int exofs_devs_2_odi(struct exofs_dt_device_info *dt_dev, |
| 388 | struct osd_dev_info *odi) |
| 389 | { |
| 390 | odi->systemid_len = le32_to_cpu(dt_dev->systemid_len); |
| 391 | memcpy(odi->systemid, dt_dev->systemid, odi->systemid_len); |
| 392 | |
| 393 | odi->osdname_len = le32_to_cpu(dt_dev->osdname_len); |
| 394 | odi->osdname = dt_dev->osdname; |
| 395 | |
| 396 | /* FIXME support long names. Will need a _put function */ |
| 397 | if (dt_dev->long_name_offset) |
| 398 | return -EINVAL; |
| 399 | |
| 400 | /* Make sure osdname is printable! |
| 401 | * mkexofs should give us space for a null-terminator else the |
| 402 | * device-table is invalid. |
| 403 | */ |
| 404 | if (unlikely(odi->osdname_len >= sizeof(dt_dev->osdname))) |
| 405 | odi->osdname_len = sizeof(dt_dev->osdname) - 1; |
| 406 | dt_dev->osdname[odi->osdname_len] = 0; |
| 407 | |
| 408 | /* If it's all zeros something is bad we read past end-of-obj */ |
| 409 | return !(odi->systemid_len || odi->osdname_len); |
| 410 | } |
| 411 | |
| 412 | static int exofs_read_lookup_dev_table(struct exofs_sb_info **psbi, |
| 413 | unsigned table_count) |
| 414 | { |
| 415 | struct exofs_sb_info *sbi = *psbi; |
| 416 | struct osd_dev *fscb_od; |
Boaz Harrosh | 45d3abc | 2010-01-28 11:46:16 +0200 | [diff] [blame] | 417 | struct osd_obj_id obj = {.partition = sbi->layout.s_pid, |
Boaz Harrosh | 04dc1e8 | 2009-11-16 16:03:05 +0200 | [diff] [blame] | 418 | .id = EXOFS_DEVTABLE_ID}; |
| 419 | struct exofs_device_table *dt; |
| 420 | unsigned table_bytes = table_count * sizeof(dt->dt_dev_table[0]) + |
| 421 | sizeof(*dt); |
| 422 | unsigned numdevs, i; |
| 423 | int ret; |
| 424 | |
| 425 | dt = kmalloc(table_bytes, GFP_KERNEL); |
| 426 | if (unlikely(!dt)) { |
| 427 | EXOFS_ERR("ERROR: allocating %x bytes for device table\n", |
| 428 | table_bytes); |
| 429 | return -ENOMEM; |
| 430 | } |
| 431 | |
Boaz Harrosh | 45d3abc | 2010-01-28 11:46:16 +0200 | [diff] [blame] | 432 | fscb_od = sbi->layout.s_ods[0]; |
| 433 | sbi->layout.s_ods[0] = NULL; |
| 434 | sbi->layout.s_numdevs = 0; |
Boaz Harrosh | 04dc1e8 | 2009-11-16 16:03:05 +0200 | [diff] [blame] | 435 | ret = exofs_read_kern(fscb_od, sbi->s_cred, &obj, 0, dt, table_bytes); |
| 436 | if (unlikely(ret)) { |
| 437 | EXOFS_ERR("ERROR: reading device table\n"); |
| 438 | goto out; |
| 439 | } |
| 440 | |
| 441 | numdevs = le64_to_cpu(dt->dt_num_devices); |
| 442 | if (unlikely(!numdevs)) { |
| 443 | ret = -EINVAL; |
| 444 | goto out; |
| 445 | } |
| 446 | WARN_ON(table_count != numdevs); |
| 447 | |
| 448 | ret = _read_and_match_data_map(sbi, numdevs, dt); |
| 449 | if (unlikely(ret)) |
| 450 | goto out; |
| 451 | |
| 452 | if (likely(numdevs > 1)) { |
Boaz Harrosh | 45d3abc | 2010-01-28 11:46:16 +0200 | [diff] [blame] | 453 | unsigned size = numdevs * sizeof(sbi->layout.s_ods[0]); |
Boaz Harrosh | 04dc1e8 | 2009-11-16 16:03:05 +0200 | [diff] [blame] | 454 | |
| 455 | sbi = krealloc(sbi, sizeof(*sbi) + size, GFP_KERNEL); |
| 456 | if (unlikely(!sbi)) { |
| 457 | ret = -ENOMEM; |
| 458 | goto out; |
| 459 | } |
Boaz Harrosh | 45d3abc | 2010-01-28 11:46:16 +0200 | [diff] [blame] | 460 | memset(&sbi->layout.s_ods[1], 0, |
| 461 | size - sizeof(sbi->layout.s_ods[0])); |
Boaz Harrosh | 04dc1e8 | 2009-11-16 16:03:05 +0200 | [diff] [blame] | 462 | *psbi = sbi; |
| 463 | } |
| 464 | |
| 465 | for (i = 0; i < numdevs; i++) { |
| 466 | struct exofs_fscb fscb; |
| 467 | struct osd_dev_info odi; |
| 468 | struct osd_dev *od; |
| 469 | |
| 470 | if (exofs_devs_2_odi(&dt->dt_dev_table[i], &odi)) { |
| 471 | EXOFS_ERR("ERROR: Read all-zeros device entry\n"); |
| 472 | ret = -EINVAL; |
| 473 | goto out; |
| 474 | } |
| 475 | |
| 476 | printk(KERN_NOTICE "Add device[%d]: osd_name-%s\n", |
| 477 | i, odi.osdname); |
| 478 | |
| 479 | /* On all devices the device table is identical. The user can |
| 480 | * specify any one of the participating devices on the command |
| 481 | * line. We always keep them in device-table order. |
| 482 | */ |
| 483 | if (fscb_od && osduld_device_same(fscb_od, &odi)) { |
Boaz Harrosh | 45d3abc | 2010-01-28 11:46:16 +0200 | [diff] [blame] | 484 | sbi->layout.s_ods[i] = fscb_od; |
| 485 | ++sbi->layout.s_numdevs; |
Boaz Harrosh | 04dc1e8 | 2009-11-16 16:03:05 +0200 | [diff] [blame] | 486 | fscb_od = NULL; |
| 487 | continue; |
| 488 | } |
| 489 | |
| 490 | od = osduld_info_lookup(&odi); |
| 491 | if (unlikely(IS_ERR(od))) { |
| 492 | ret = PTR_ERR(od); |
| 493 | EXOFS_ERR("ERROR: device requested is not found " |
| 494 | "osd_name-%s =>%d\n", odi.osdname, ret); |
| 495 | goto out; |
| 496 | } |
| 497 | |
Boaz Harrosh | 45d3abc | 2010-01-28 11:46:16 +0200 | [diff] [blame] | 498 | sbi->layout.s_ods[i] = od; |
| 499 | ++sbi->layout.s_numdevs; |
Boaz Harrosh | 04dc1e8 | 2009-11-16 16:03:05 +0200 | [diff] [blame] | 500 | |
| 501 | /* Read the fscb of the other devices to make sure the FS |
| 502 | * partition is there. |
| 503 | */ |
| 504 | ret = exofs_read_kern(od, sbi->s_cred, &obj, 0, &fscb, |
| 505 | sizeof(fscb)); |
| 506 | if (unlikely(ret)) { |
| 507 | EXOFS_ERR("ERROR: Malformed participating device " |
| 508 | "error reading fscb osd_name-%s\n", |
| 509 | odi.osdname); |
| 510 | goto out; |
| 511 | } |
| 512 | |
| 513 | /* TODO: verify other information is correct and FS-uuid |
| 514 | * matches. Benny what did you say about device table |
| 515 | * generation and old devices? |
| 516 | */ |
| 517 | } |
| 518 | |
| 519 | out: |
| 520 | kfree(dt); |
| 521 | if (unlikely(!ret && fscb_od)) { |
| 522 | EXOFS_ERR( |
| 523 | "ERROR: Bad device-table container device not present\n"); |
| 524 | osduld_put_device(fscb_od); |
| 525 | ret = -EINVAL; |
| 526 | } |
| 527 | |
| 528 | return ret; |
| 529 | } |
| 530 | |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 531 | /* |
| 532 | * Read the superblock from the OSD and fill in the fields |
| 533 | */ |
| 534 | static int exofs_fill_super(struct super_block *sb, void *data, int silent) |
| 535 | { |
| 536 | struct inode *root; |
| 537 | struct exofs_mountopt *opts = data; |
| 538 | struct exofs_sb_info *sbi; /*extended info */ |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 539 | struct osd_dev *od; /* Master device */ |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 540 | struct exofs_fscb fscb; /*on-disk superblock info */ |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 541 | struct osd_obj_id obj; |
Boaz Harrosh | 04dc1e8 | 2009-11-16 16:03:05 +0200 | [diff] [blame] | 542 | unsigned table_count; |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 543 | int ret; |
| 544 | |
| 545 | sbi = kzalloc(sizeof(*sbi), GFP_KERNEL); |
| 546 | if (!sbi) |
| 547 | return -ENOMEM; |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 548 | |
Jens Axboe | b3d0ab7 | 2010-04-22 12:26:04 +0200 | [diff] [blame] | 549 | ret = bdi_setup_and_register(&sbi->bdi, "exofs", BDI_CAP_MAP_COPY); |
| 550 | if (ret) |
| 551 | goto free_bdi; |
| 552 | |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 553 | /* use mount options to fill superblock */ |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 554 | od = osduld_path_lookup(opts->dev_name); |
| 555 | if (IS_ERR(od)) { |
| 556 | ret = PTR_ERR(od); |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 557 | goto free_sbi; |
| 558 | } |
| 559 | |
Boaz Harrosh | 45d3abc | 2010-01-28 11:46:16 +0200 | [diff] [blame] | 560 | /* Default layout in case we do not have a device-table */ |
Boaz Harrosh | 5d952b8 | 2010-02-01 13:35:51 +0200 | [diff] [blame] | 561 | sbi->layout.stripe_unit = PAGE_SIZE; |
| 562 | sbi->layout.mirrors_p1 = 1; |
| 563 | sbi->layout.group_width = 1; |
Boaz Harrosh | 50a76fd | 2010-02-11 13:01:39 +0200 | [diff] [blame] | 564 | sbi->layout.group_depth = -1; |
| 565 | sbi->layout.group_count = 1; |
Boaz Harrosh | 45d3abc | 2010-01-28 11:46:16 +0200 | [diff] [blame] | 566 | sbi->layout.s_ods[0] = od; |
| 567 | sbi->layout.s_numdevs = 1; |
| 568 | sbi->layout.s_pid = opts->pid; |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 569 | sbi->s_timeout = opts->timeout; |
| 570 | |
| 571 | /* fill in some other data by hand */ |
| 572 | memset(sb->s_id, 0, sizeof(sb->s_id)); |
| 573 | strcpy(sb->s_id, "exofs"); |
| 574 | sb->s_blocksize = EXOFS_BLKSIZE; |
| 575 | sb->s_blocksize_bits = EXOFS_BLKSHIFT; |
| 576 | sb->s_maxbytes = MAX_LFS_FILESIZE; |
| 577 | atomic_set(&sbi->s_curr_pending, 0); |
| 578 | sb->s_bdev = NULL; |
| 579 | sb->s_dev = 0; |
| 580 | |
Boaz Harrosh | 45d3abc | 2010-01-28 11:46:16 +0200 | [diff] [blame] | 581 | obj.partition = sbi->layout.s_pid; |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 582 | obj.id = EXOFS_SUPER_ID; |
| 583 | exofs_make_credential(sbi->s_cred, &obj); |
| 584 | |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 585 | ret = exofs_read_kern(od, sbi->s_cred, &obj, 0, &fscb, sizeof(fscb)); |
| 586 | if (unlikely(ret)) |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 587 | goto free_sbi; |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 588 | |
| 589 | sb->s_magic = le16_to_cpu(fscb.s_magic); |
| 590 | sbi->s_nextid = le64_to_cpu(fscb.s_nextid); |
| 591 | sbi->s_numfiles = le32_to_cpu(fscb.s_numfiles); |
| 592 | |
| 593 | /* make sure what we read from the object store is correct */ |
| 594 | if (sb->s_magic != EXOFS_SUPER_MAGIC) { |
| 595 | if (!silent) |
| 596 | EXOFS_ERR("ERROR: Bad magic value\n"); |
| 597 | ret = -EINVAL; |
| 598 | goto free_sbi; |
| 599 | } |
Boaz Harrosh | 04dc1e8 | 2009-11-16 16:03:05 +0200 | [diff] [blame] | 600 | if (le32_to_cpu(fscb.s_version) != EXOFS_FSCB_VER) { |
| 601 | EXOFS_ERR("ERROR: Bad FSCB version expected-%d got-%d\n", |
| 602 | EXOFS_FSCB_VER, le32_to_cpu(fscb.s_version)); |
| 603 | ret = -EINVAL; |
| 604 | goto free_sbi; |
| 605 | } |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 606 | |
| 607 | /* start generation numbers from a random point */ |
| 608 | get_random_bytes(&sbi->s_next_generation, sizeof(u32)); |
| 609 | spin_lock_init(&sbi->s_next_gen_lock); |
| 610 | |
Boaz Harrosh | 04dc1e8 | 2009-11-16 16:03:05 +0200 | [diff] [blame] | 611 | table_count = le64_to_cpu(fscb.s_dev_table_count); |
| 612 | if (table_count) { |
| 613 | ret = exofs_read_lookup_dev_table(&sbi, table_count); |
| 614 | if (unlikely(ret)) |
| 615 | goto free_sbi; |
| 616 | } |
| 617 | |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 618 | /* set up operation vectors */ |
Jens Axboe | b3d0ab7 | 2010-04-22 12:26:04 +0200 | [diff] [blame] | 619 | sb->s_bdi = &sbi->bdi; |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 620 | sb->s_fs_info = sbi; |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 621 | sb->s_op = &exofs_sops; |
Boaz Harrosh | 8cf74b3 | 2009-03-22 12:47:26 +0200 | [diff] [blame] | 622 | sb->s_export_op = &exofs_export_ops; |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 623 | root = exofs_iget(sb, EXOFS_ROOT_ID - EXOFS_OBJ_OFF); |
| 624 | if (IS_ERR(root)) { |
| 625 | EXOFS_ERR("ERROR: exofs_iget failed\n"); |
| 626 | ret = PTR_ERR(root); |
| 627 | goto free_sbi; |
| 628 | } |
| 629 | sb->s_root = d_alloc_root(root); |
| 630 | if (!sb->s_root) { |
| 631 | iput(root); |
| 632 | EXOFS_ERR("ERROR: get root inode failed\n"); |
| 633 | ret = -ENOMEM; |
| 634 | goto free_sbi; |
| 635 | } |
| 636 | |
| 637 | if (!S_ISDIR(root->i_mode)) { |
| 638 | dput(sb->s_root); |
| 639 | sb->s_root = NULL; |
| 640 | EXOFS_ERR("ERROR: corrupt root inode (mode = %hd)\n", |
| 641 | root->i_mode); |
| 642 | ret = -EINVAL; |
| 643 | goto free_sbi; |
| 644 | } |
| 645 | |
Boaz Harrosh | 45d3abc | 2010-01-28 11:46:16 +0200 | [diff] [blame] | 646 | _exofs_print_device("Mounting", opts->dev_name, sbi->layout.s_ods[0], |
| 647 | sbi->layout.s_pid); |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 648 | return 0; |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 649 | |
| 650 | free_sbi: |
Jens Axboe | b3d0ab7 | 2010-04-22 12:26:04 +0200 | [diff] [blame] | 651 | bdi_destroy(&sbi->bdi); |
| 652 | free_bdi: |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 653 | EXOFS_ERR("Unable to mount exofs on %s pid=0x%llx err=%d\n", |
Boaz Harrosh | 45d3abc | 2010-01-28 11:46:16 +0200 | [diff] [blame] | 654 | opts->dev_name, sbi->layout.s_pid, ret); |
Boaz Harrosh | 04dc1e8 | 2009-11-16 16:03:05 +0200 | [diff] [blame] | 655 | exofs_free_sbi(sbi); |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 656 | return ret; |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | /* |
| 660 | * Set up the superblock (calls exofs_fill_super eventually) |
| 661 | */ |
| 662 | static int exofs_get_sb(struct file_system_type *type, |
| 663 | int flags, const char *dev_name, |
| 664 | void *data, struct vfsmount *mnt) |
| 665 | { |
| 666 | struct exofs_mountopt opts; |
| 667 | int ret; |
| 668 | |
| 669 | ret = parse_options(data, &opts); |
| 670 | if (ret) |
| 671 | return ret; |
| 672 | |
| 673 | opts.dev_name = dev_name; |
| 674 | return get_sb_nodev(type, flags, &opts, exofs_fill_super, mnt); |
| 675 | } |
| 676 | |
| 677 | /* |
| 678 | * Return information about the file system state in the buffer. This is used |
| 679 | * by the 'df' command, for example. |
| 680 | */ |
| 681 | static int exofs_statfs(struct dentry *dentry, struct kstatfs *buf) |
| 682 | { |
| 683 | struct super_block *sb = dentry->d_sb; |
| 684 | struct exofs_sb_info *sbi = sb->s_fs_info; |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 685 | struct exofs_io_state *ios; |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 686 | struct osd_attr attrs[] = { |
| 687 | ATTR_DEF(OSD_APAGE_PARTITION_QUOTAS, |
| 688 | OSD_ATTR_PQ_CAPACITY_QUOTA, sizeof(__be64)), |
| 689 | ATTR_DEF(OSD_APAGE_PARTITION_INFORMATION, |
| 690 | OSD_ATTR_PI_USED_CAPACITY, sizeof(__be64)), |
| 691 | }; |
| 692 | uint64_t capacity = ULLONG_MAX; |
| 693 | uint64_t used = ULLONG_MAX; |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 694 | uint8_t cred_a[OSD_CAP_LEN]; |
| 695 | int ret; |
| 696 | |
Boaz Harrosh | 45d3abc | 2010-01-28 11:46:16 +0200 | [diff] [blame] | 697 | ret = exofs_get_io_state(&sbi->layout, &ios); |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 698 | if (ret) { |
| 699 | EXOFS_DBGMSG("exofs_get_io_state failed.\n"); |
| 700 | return ret; |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 701 | } |
| 702 | |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 703 | exofs_make_credential(cred_a, &ios->obj); |
| 704 | ios->cred = sbi->s_cred; |
| 705 | ios->in_attr = attrs; |
| 706 | ios->in_attr_len = ARRAY_SIZE(attrs); |
| 707 | |
| 708 | ret = exofs_sbi_read(ios); |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 709 | if (unlikely(ret)) |
| 710 | goto out; |
| 711 | |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 712 | ret = extract_attr_from_ios(ios, &attrs[0]); |
Boaz Harrosh | cae012d | 2009-11-02 18:19:24 +0200 | [diff] [blame] | 713 | if (likely(!ret)) { |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 714 | capacity = get_unaligned_be64(attrs[0].val_ptr); |
Boaz Harrosh | cae012d | 2009-11-02 18:19:24 +0200 | [diff] [blame] | 715 | if (unlikely(!capacity)) |
| 716 | capacity = ULLONG_MAX; |
| 717 | } else |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 718 | EXOFS_DBGMSG("exofs_statfs: get capacity failed.\n"); |
| 719 | |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 720 | ret = extract_attr_from_ios(ios, &attrs[1]); |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 721 | if (likely(!ret)) |
| 722 | used = get_unaligned_be64(attrs[1].val_ptr); |
| 723 | else |
| 724 | EXOFS_DBGMSG("exofs_statfs: get used-space failed.\n"); |
| 725 | |
| 726 | /* fill in the stats buffer */ |
| 727 | buf->f_type = EXOFS_SUPER_MAGIC; |
| 728 | buf->f_bsize = EXOFS_BLKSIZE; |
Boaz Harrosh | cae012d | 2009-11-02 18:19:24 +0200 | [diff] [blame] | 729 | buf->f_blocks = capacity >> 9; |
| 730 | buf->f_bfree = (capacity - used) >> 9; |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 731 | buf->f_bavail = buf->f_bfree; |
| 732 | buf->f_files = sbi->s_numfiles; |
| 733 | buf->f_ffree = EXOFS_MAX_ID - sbi->s_numfiles; |
| 734 | buf->f_namelen = EXOFS_NAME_LEN; |
| 735 | |
| 736 | out: |
Boaz Harrosh | 06886a5 | 2009-11-08 14:54:08 +0200 | [diff] [blame] | 737 | exofs_put_io_state(ios); |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 738 | return ret; |
| 739 | } |
| 740 | |
| 741 | static const struct super_operations exofs_sops = { |
| 742 | .alloc_inode = exofs_alloc_inode, |
| 743 | .destroy_inode = exofs_destroy_inode, |
| 744 | .write_inode = exofs_write_inode, |
Al Viro | 4ec70c9 | 2010-06-07 11:42:26 -0400 | [diff] [blame] | 745 | .evict_inode = exofs_evict_inode, |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 746 | .put_super = exofs_put_super, |
| 747 | .write_super = exofs_write_super, |
Christoph Hellwig | 80e09fb | 2009-06-08 10:03:58 +0200 | [diff] [blame] | 748 | .sync_fs = exofs_sync_fs, |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 749 | .statfs = exofs_statfs, |
| 750 | }; |
| 751 | |
| 752 | /****************************************************************************** |
Boaz Harrosh | 8cf74b3 | 2009-03-22 12:47:26 +0200 | [diff] [blame] | 753 | * EXPORT OPERATIONS |
| 754 | *****************************************************************************/ |
| 755 | |
| 756 | struct dentry *exofs_get_parent(struct dentry *child) |
| 757 | { |
| 758 | unsigned long ino = exofs_parent_ino(child); |
| 759 | |
| 760 | if (!ino) |
| 761 | return NULL; |
| 762 | |
| 763 | return d_obtain_alias(exofs_iget(child->d_inode->i_sb, ino)); |
| 764 | } |
| 765 | |
| 766 | static struct inode *exofs_nfs_get_inode(struct super_block *sb, |
| 767 | u64 ino, u32 generation) |
| 768 | { |
| 769 | struct inode *inode; |
| 770 | |
| 771 | inode = exofs_iget(sb, ino); |
| 772 | if (IS_ERR(inode)) |
| 773 | return ERR_CAST(inode); |
| 774 | if (generation && inode->i_generation != generation) { |
| 775 | /* we didn't find the right inode.. */ |
| 776 | iput(inode); |
| 777 | return ERR_PTR(-ESTALE); |
| 778 | } |
| 779 | return inode; |
| 780 | } |
| 781 | |
| 782 | static struct dentry *exofs_fh_to_dentry(struct super_block *sb, |
| 783 | struct fid *fid, int fh_len, int fh_type) |
| 784 | { |
| 785 | return generic_fh_to_dentry(sb, fid, fh_len, fh_type, |
| 786 | exofs_nfs_get_inode); |
| 787 | } |
| 788 | |
| 789 | static struct dentry *exofs_fh_to_parent(struct super_block *sb, |
| 790 | struct fid *fid, int fh_len, int fh_type) |
| 791 | { |
| 792 | return generic_fh_to_parent(sb, fid, fh_len, fh_type, |
| 793 | exofs_nfs_get_inode); |
| 794 | } |
| 795 | |
| 796 | static const struct export_operations exofs_export_ops = { |
| 797 | .fh_to_dentry = exofs_fh_to_dentry, |
| 798 | .fh_to_parent = exofs_fh_to_parent, |
| 799 | .get_parent = exofs_get_parent, |
| 800 | }; |
| 801 | |
| 802 | /****************************************************************************** |
Boaz Harrosh | ba9e5e9 | 2008-10-28 16:11:41 +0200 | [diff] [blame] | 803 | * INSMOD/RMMOD |
| 804 | *****************************************************************************/ |
| 805 | |
| 806 | /* |
| 807 | * struct that describes this file system |
| 808 | */ |
| 809 | static struct file_system_type exofs_type = { |
| 810 | .owner = THIS_MODULE, |
| 811 | .name = "exofs", |
| 812 | .get_sb = exofs_get_sb, |
| 813 | .kill_sb = generic_shutdown_super, |
| 814 | }; |
| 815 | |
| 816 | static int __init init_exofs(void) |
| 817 | { |
| 818 | int err; |
| 819 | |
| 820 | err = init_inodecache(); |
| 821 | if (err) |
| 822 | goto out; |
| 823 | |
| 824 | err = register_filesystem(&exofs_type); |
| 825 | if (err) |
| 826 | goto out_d; |
| 827 | |
| 828 | return 0; |
| 829 | out_d: |
| 830 | destroy_inodecache(); |
| 831 | out: |
| 832 | return err; |
| 833 | } |
| 834 | |
| 835 | static void __exit exit_exofs(void) |
| 836 | { |
| 837 | unregister_filesystem(&exofs_type); |
| 838 | destroy_inodecache(); |
| 839 | } |
| 840 | |
| 841 | MODULE_AUTHOR("Avishay Traeger <avishay@gmail.com>"); |
| 842 | MODULE_DESCRIPTION("exofs"); |
| 843 | MODULE_LICENSE("GPL"); |
| 844 | |
| 845 | module_init(init_exofs) |
| 846 | module_exit(exit_exofs) |