Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 | /* * presto's super.c * * Copyright (C) 1998 Peter J. Braam * Copyright (C) 2000 Stelias Computing, Inc. * Copyright (C) 2000 Red Hat, Inc. * * */ #include <stdarg.h> #include <asm/bitops.h> #include <asm/uaccess.h> #include <asm/system.h> #include <linux/errno.h> #include <linux/fs.h> #include <linux/ext2_fs.h> #include <linux/slab.h> #include <linux/vmalloc.h> #include <linux/time.h> #include <linux/stat.h> #include <linux/string.h> #include <linux/blkdev.h> #include <linux/init.h> #define __NO_VERSION__ #include <linux/module.h> #include <linux/intermezzo_fs.h> #include <linux/intermezzo_upcall.h> #include <linux/intermezzo_psdev.h> #ifdef PRESTO_DEBUG long presto_vmemory = 0; long presto_kmemory = 0; #endif extern struct presto_cache *presto_init_cache(void); extern inline void presto_cache_add(struct presto_cache *cache, struct super_block *sb); extern inline void presto_init_cache_hash(void); int presto_remount(struct super_block *, int *, char *); extern ssize_t presto_file_write(struct file *file, const char *buf, size_t size, loff_t *off); /* * Reading the super block. * * * */ /* returns an allocated string, copied out from data if opt is found */ static char *read_opt(const char *opt, char *data) { char *value; char *retval; CDEBUG(D_SUPER, "option: %s, data %s\n", opt, data); if ( strncmp(opt, data, strlen(opt)) ) return NULL; if ( (value = strchr(data, '=')) == NULL ) return NULL; value++; PRESTO_ALLOC(retval, char *, strlen(value) + 1); if ( !retval ) { printk("InterMezzo: Out of memory!\n"); return NULL; } strcpy(retval, value); CDEBUG(D_SUPER, "Assigned option: %s, value %s\n", opt, retval); return retval; } static void store_opt(char **dst, char *opt, char *defval) { if (dst) { if (*dst) { PRESTO_FREE(*dst, strlen(*dst) + 1); } *dst = opt; } else { printk("presto: store_opt, error dst == NULL\n"); } if (!opt && defval) { char *def_alloced; PRESTO_ALLOC(def_alloced, char *, strlen(defval)+1); strcpy(def_alloced, defval); *dst = def_alloced; } } /* Find the options for InterMezzo in "options", saving them into the * passed pointers. If the pointer is null, the option is discarded. * Copy out all non-InterMezzo options into cache_data (to be passed * to the read_super operation of the cache). The return value will * be a pointer to the end of the cache_data. */ static char *presto_options(char *options, char *cache_data, char **cache_type, char **fileset, char **prestodev, char **mtpt) { char *this_char; char *cache_data_end = cache_data; if (!options || !cache_data) return cache_data_end; /* set the defaults */ store_opt(cache_type, NULL, "ext3"); store_opt(prestodev, NULL, PRESTO_PSDEV_NAME "0"); CDEBUG(D_SUPER, "parsing options\n"); while ((this_char = strsep (&options, ",")) != NULL) { char *opt; CDEBUG(D_SUPER, "this_char %s\n", this_char); if (!*this_char) continue; if ( (opt = read_opt("fileset", this_char)) ) { store_opt(fileset, opt, NULL); continue; } if ( (opt = read_opt("cache_type", this_char)) ) { store_opt(cache_type, opt, "ext3"); continue; } if ( (opt = read_opt("mtpt", this_char)) ) { store_opt(mtpt, opt, NULL); continue; } if ( (opt = read_opt("prestodev", this_char)) ) { store_opt(prestodev, opt, PRESTO_PSDEV_NAME); continue; } cache_data_end += sprintf(cache_data_end, "%s%s", cache_data_end != cache_data ? ",":"", this_char); } return cache_data_end; } /* map a /dev/intermezzoX path to a minor: used to validate mount options passed to InterMezzo */ static int presto_get_minor(char *dev_path, int *minor) { struct nameidata nd; struct dentry *dentry; kdev_t devno = NODEV; int error; ENTRY; /* Special case for root filesystem - use minor 0 always. */ if ( current->pid == 1 ) { *minor = 0; return 0; } error = presto_walk(dev_path, &nd); if (error) { EXIT; return error; } dentry = nd.dentry; error = -ENODEV; if (!dentry->d_inode) { EXIT; goto out; } if (!S_ISCHR(dentry->d_inode->i_mode)) { EXIT; goto out; } devno = dentry->d_inode->i_rdev; if ( major(devno) != PRESTO_PSDEV_MAJOR ) { EXIT; goto out; } if ( minor(devno) >= MAX_PRESTODEV ) { EXIT; goto out; } EXIT; out: *minor = minor(devno); path_release(&nd); return 0; } /* We always need to remove the presto options before passing to bottom FS */ struct super_block * presto_read_super(struct super_block * presto_sb, void * data, int silent) { struct super_block *mysb = NULL; struct file_system_type *fstype; struct presto_cache *cache = NULL; char *cache_data = NULL; char *cache_data_end; char *cache_type = NULL; char *fileset = NULL; char *presto_mtpt = NULL; char *prestodev = NULL; struct filter_fs *ops; int minor; struct upc_comm *psdev; ENTRY; CDEBUG(D_MALLOC, "before parsing: kmem %ld, vmem %ld\n", presto_kmemory, presto_vmemory); /* reserve space for the cache's data */ PRESTO_ALLOC(cache_data, void *, PAGE_SIZE); if ( !cache_data ) { printk("presto_read_super: Cannot allocate data page.\n"); EXIT; goto out_err; } CDEBUG(D_SUPER, "mount opts: %s\n", data ? (char *)data : "(none)"); /* read and validate options */ cache_data_end = presto_options(data, cache_data, &cache_type, &fileset, &prestodev, &presto_mtpt); /* was there anything for the cache filesystem in the data? */ if (cache_data_end == cache_data) { PRESTO_FREE(cache_data, PAGE_SIZE); cache_data = NULL; } else { CDEBUG(D_SUPER, "cache_data at %p is: %s\n", cache_data, cache_data); } /* prepare the communication channel */ if ( presto_get_minor(prestodev, &minor) ) { /* if (!silent) */ printk("InterMezzo: %s not a valid presto dev\n", prestodev); EXIT; goto out_err; } psdev = &upc_comms[minor]; CDEBUG(D_SUPER, "\n"); psdev->uc_no_filter = 1; CDEBUG(D_SUPER, "presto minor is %d\n", minor); /* set up the cache */ cache = presto_init_cache(); if ( !cache ) { printk("presto_read_super: failure allocating cache.\n"); EXIT; goto out_err; } /* no options were passed: likely we are "/" readonly */ if ( !presto_mtpt || !fileset ) { cache->cache_flags |= CACHE_LENTO_RO | CACHE_CLIENT_RO; } cache->cache_psdev = psdev; /* no options were passed: likely we are "/" readonly */ /* before the journaling infrastructure can work, these need to be set; that happens in presto_remount */ if ( !presto_mtpt || !fileset ) { if (!presto_mtpt) printk("No mountpoint marking cache RO\n"); if (!fileset) printk("No fileset marking cache RO\n"); cache->cache_flags |= CACHE_LENTO_RO | CACHE_CLIENT_RO; } cache->cache_mtpt = presto_mtpt; cache->cache_root_fileset = fileset; cache->cache_type = cache_type; printk("Presto: type=%s, vol=%s, dev=%s (minor %d), mtpt %s, flags %x\n", cache_type, fileset ? fileset : "NULL", prestodev, minor, presto_mtpt ? presto_mtpt : "NULL", cache->cache_flags); MOD_INC_USE_COUNT; fstype = get_fs_type(cache_type); cache->cache_filter = filter_get_filter_fs((const char *)cache_type); if ( !fstype || !cache->cache_filter) { printk("Presto: unrecognized fs type or cache type\n"); MOD_DEC_USE_COUNT; EXIT; goto out_err; } mysb = fstype->read_super(presto_sb, cache_data, silent); /* this might have been freed above */ if (cache_data) { PRESTO_FREE(cache_data, PAGE_SIZE); cache_data = NULL; } if ( !mysb ) { /* if (!silent) */ printk("InterMezzo: cache mount failure.\n"); MOD_DEC_USE_COUNT; EXIT; goto out_err; } cache->cache_sb = mysb; ops = filter_get_filter_fs(cache_type); filter_setup_journal_ops(cache->cache_filter, cache->cache_type); /* we now know the dev of the cache: hash the cache */ presto_cache_add(cache, mysb); /* make sure we have our own super operations: mysb still contains the cache operations */ filter_setup_super_ops(cache->cache_filter, mysb->s_op, &presto_super_ops); mysb->s_op = filter_c2usops(cache->cache_filter); /* now get our own directory operations */ if ( mysb->s_root && mysb->s_root->d_inode ) { CDEBUG(D_SUPER, "\n"); filter_setup_dir_ops(cache->cache_filter, mysb->s_root->d_inode, &presto_dir_iops, &presto_dir_fops); mysb->s_root->d_inode->i_op = filter_c2udiops(cache->cache_filter); CDEBUG(D_SUPER, "lookup at %p\n", mysb->s_root->d_inode->i_op->lookup); filter_setup_dentry_ops(cache->cache_filter, mysb->s_root->d_op, &presto_dentry_ops); presto_sb->s_root->d_op = filter_c2udops(cache->cache_filter); cache->cache_mtde = mysb->s_root; presto_set_dd(mysb->s_root); } CDEBUG(D_MALLOC, "after mounting: kmem %ld, vmem %ld\n", presto_kmemory, presto_vmemory); EXIT; return mysb; out_err: CDEBUG(D_SUPER, "out_err called\n"); if (cache) PRESTO_FREE(cache, sizeof(struct presto_cache)); if (cache_data) PRESTO_FREE(cache_data, PAGE_SIZE); if (fileset) PRESTO_FREE(fileset, strlen(fileset) + 1); if (presto_mtpt) PRESTO_FREE(presto_mtpt, strlen(presto_mtpt) + 1); if (prestodev) PRESTO_FREE(prestodev, strlen(prestodev) + 1); if (cache_type) PRESTO_FREE(cache_type, strlen(cache_type) + 1); CDEBUG(D_MALLOC, "mount error exit: kmem %ld, vmem %ld\n", presto_kmemory, presto_vmemory); return NULL; } int presto_remount(struct super_block * sb, int *flags, char *data) { char *cache_data = NULL; char *cache_data_end; char **type; char **fileset; char **mtpt; char **prestodev; struct super_operations *sops; struct presto_cache *cache = NULL; int err = 0; ENTRY; CDEBUG(D_MALLOC, "before remount: kmem %ld, vmem %ld\n", presto_kmemory, presto_vmemory); CDEBUG(D_SUPER, "remount opts: %s\n", data ? (char *)data : "(none)"); if (data) { /* reserve space for the cache's data */ PRESTO_ALLOC(cache_data, void *, PAGE_SIZE); if ( !cache_data ) { err = -ENOMEM; EXIT; goto out_err; } } cache = presto_find_cache(sb); if (!cache) { printk(__FUNCTION__ ": cannot find cache on remount\n"); err = -ENODEV; EXIT; goto out_err; } /* If an option has not yet been set, we allow it to be set on * remount. If an option already has a value, we pass NULL for * the option pointer, which means that the InterMezzo option * will be parsed but discarded. */ type = cache->cache_type ? NULL : &cache->cache_type; fileset = cache->cache_root_fileset ? NULL : &cache->cache_root_fileset; prestodev = cache->cache_psdev ? NULL : &cache->cache_psdev->uc_devname; mtpt = cache->cache_mtpt ? NULL : &cache->cache_mtpt; cache_data_end = presto_options(data, cache_data, type, fileset, prestodev, mtpt); if (cache_data) { if (cache_data_end == cache_data) { PRESTO_FREE(cache_data, PAGE_SIZE); cache_data = NULL; } else { CDEBUG(D_SUPER, "cache_data at %p is: %s\n", cache_data, cache_data); } } if (cache->cache_root_fileset && cache->cache_mtpt) { cache->cache_flags &= ~(CACHE_LENTO_RO|CACHE_CLIENT_RO); } sops = filter_c2csops(cache->cache_filter); if (sops->remount_fs) { err = sops->remount_fs(sb, flags, cache_data); } CDEBUG(D_MALLOC, "after remount: kmem %ld, vmem %ld\n", presto_kmemory, presto_vmemory); EXIT; out_err: if (cache_data) PRESTO_FREE(cache_data, PAGE_SIZE); return err; } struct file_system_type presto_fs_type = { #ifdef PRESTO_DEVEL "izofs", #else "intermezzo", #endif FS_REQUIRES_DEV, /* can use Ibaskets when ext2 does */ presto_read_super, NULL }; int /* __init */ init_intermezzo_fs(void) { int status; printk(KERN_INFO "InterMezzo Kernel/Lento communications, " "v1.04, braam@inter-mezzo.org\n"); status = presto_psdev_init(); if ( status ) { printk("Problem (%d) in init_intermezzo_psdev\n", status); return status; } status = init_intermezzo_sysctl(); if (status) { printk("presto: failed in init_intermezzo_sysctl!\n"); } presto_init_cache_hash(); presto_init_ddata_cache(); status = register_filesystem(&presto_fs_type); if (status) { printk("presto: failed in register_filesystem!\n"); } return status; } #ifdef MODULE MODULE_AUTHOR("Peter J. Braam <braam@inter-mezzo.org>"); MODULE_DESCRIPTION("InterMezzo Kernel/Lento communications, v1.0.5.1"); int init_module(void) { return init_intermezzo_fs(); } void cleanup_module(void) { int err; ENTRY; if ( (err = unregister_filesystem(&presto_fs_type)) != 0 ) { printk("presto: failed to unregister filesystem\n"); } presto_psdev_cleanup(); cleanup_intermezzo_sysctl(); presto_cleanup_ddata_cache(); #ifdef PRESTO_DEVEL unregister_chrdev(PRESTO_PSDEV_MAJOR, "intermezzo_psdev_devel"); #else unregister_chrdev(PRESTO_PSDEV_MAJOR, "intermezzo_psdev"); #endif CDEBUG(D_MALLOC, "after cleanup: kmem %ld, vmem %ld\n", presto_kmemory, presto_vmemory); } #endif |