📄 super.c
字号:
/* * 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/sched.h>#include <linux/stat.h>#include <linux/string.h>#include <linux/locks.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_DEBUGlong presto_vmemory = 0;long presto_kmemory = 0;#endifextern struct presto_cache *presto_init_cache(void);extern inline void presto_cache_add(struct presto_cache *cache, kdev_t dev);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"); for (this_char = strtok (options, ","); this_char != NULL; this_char = strtok (NULL, ",")) { char *opt; CDEBUG(D_SUPER, "this_char %s\n", this_char); 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 = 0; 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);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -