From c5ecb802fcf277446aa33f7372cb38e235f7cd3b Mon Sep 17 00:00:00 2001 From: Steven Whitehouse Date: Mon, 24 Sep 2001 15:10:33 +0000 Subject: [PATCH] Well when things start looking so complicated that future direction becomes non-obvious, its time to simplify :-) o Moving towards a simpler and more obviously correct interface o Removed some fs operations in directories representing volumes o Changed some file names o Made things cleaner more changes to follow... --- driver/device-mapper/dmfs-active.c | 73 ---------------- driver/device-mapper/dmfs-lv.c | 135 +++-------------------------- driver/device-mapper/dmfs-table.c | 18 +++- 3 files changed, 28 insertions(+), 198 deletions(-) delete mode 100644 driver/device-mapper/dmfs-active.c diff --git a/driver/device-mapper/dmfs-active.c b/driver/device-mapper/dmfs-active.c deleted file mode 100644 index 28afe1435..000000000 --- a/driver/device-mapper/dmfs-active.c +++ /dev/null @@ -1,73 +0,0 @@ -/* - * dmfs-active.c - * - * Copyright (C) 2001 Sistina Software - * - * This software is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2, or (at - * your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with GNU CC; see the file COPYING. If not, write to - * the Free Software Foundation, 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include -#include - -static ssize_t dmfs_active_read(struct file *file, char *buf, size_t size, loff_t *pos) -{ - down(&inode->i_sem); - - up(&inode->i_sem); -} - -static ssize_t dmfs_active_write(struct file *file, const char *buf, size_t size, loff_t *pos) -{ - down(&inode->i_sem); - - up(&inode->i_sem); -} - -static int dmfs_active_sync(struct file *file, struct dentry *dentry, int datasync) -{ - return 0; -} - -static struct dm_table_file_operations = { -/* llseek: generic_file_llseek, */ - read: dmfs_active_read, - write: dmfs_active_write, - open: dmfs_active_open, - fsync: dmfs_active_sync, -}; - -static struct dmfs_active_inode_operations = { -}; - -int dmfs_create_active(struct inode *dir, int mode) -{ - struct inode *inode = new_inode(dir->i_sb); - - if (inode) { - inode->i_mode = mode | S_IFREG; - inode->i_uid = current->fsuid; - inode->i_gid = current->fsgid; - inode->i_blksize = PAGE_CACHE_SIZE; - inode->i_blocks = 0; - inode->i_rdev = NODEV; - inode->i_atime = inode->i_ctime = inode->i_mtime = CURRENT_TIME; - inode->i_fop = &dmfs_active_file_operations; - inode->i_op = &dmfs_active_inode_operations; - } - - return inode; -} - diff --git a/driver/device-mapper/dmfs-lv.c b/driver/device-mapper/dmfs-lv.c index c78487479..c20e956e3 100644 --- a/driver/device-mapper/dmfs-lv.c +++ b/driver/device-mapper/dmfs-lv.c @@ -24,32 +24,6 @@ #include #include -static int dmfs_lv_create(struct inode *dir, struct dentry *dentry, int mode) -{ - struct inode *inode; - struct dm_table *table; - - if (dentry->d_name.name[0] == '.') - return -EPERM; - - if (dentry->d_name.len == 6 && - memcmp(dentry->d_name.name, "ACTIVE", 6) == 0) - return -EPERM; - - inode = dmfs_create_table(dir, dentry, mode) - if (!IS_ERR(inode)) { - table = dm_table_create(); - if (table) { - d_instantiate(dentry, inode); - dget(dentry); - return 0; - } - iput(inode); - return -ENOMEM; - } - return PTR_ERR(inode); -} - static int dmfs_lv_unlink(struct inode *dir, struct dentry *dentry) { inode->i_nlink--; @@ -57,72 +31,26 @@ static int dmfs_lv_unlink(struct inode *dir, struct dentry *dentry) return 0; } -static int dmfs_lv_link(struct dentry *old_dentry, struct inode *dir, struct dentry *dentry) -{ - struct inode *inode = old_dentry->d_inode; - - if (!S_ISREG(inode->i_mode)) - return -EPERM; - - if (dentry->d_parent != old_dentry->d_parent) - return -EPERM; - - if (dentry->d_name[0] == '.') - return -EPERM; - - if (old_dentry->d_name[0] == '.') - return -EPERM; - - inode->i_nlink++; - atomic_inc(&inode->i_count); - dget(dentry); - d_instantiate(dentry, inode); - - return 0; -} - static struct dentry *dmfs_lv_lookup(struct inode *dir, struct dentry *dentry) { struct inode *inode = NULL; - - if (dentry->d_name[0] == '.') { - char *name = dentry->d_name.name; - switch(dentry->d_name.len) { - case 7: - if (memcmp(".active", name, 7) == 0) - inode = dmfs_create_active(dir, 0600); - break; - case 11: - if (memcmp(".suspend_IO", name, 11) == 0) - inode = dmfs_create_suspend(dir, 0600); - break; - } + char *name = dentry->d_name.name; + + switch(dentry->d_name.len) { + case 5: + if (memcmp("table", name, 5) == 0) + inode = dmfs_create_table(dir, 0600); + break; + case 10: + if (memcmp("suspend_IO", name, 10) == 0) + inode = dmfs_create_suspend(dir, 0600); + break; } d_add(dentry, inode); return NULL; } -static int dmfs_lv_rename(struct inode *old_dir, struct dentry *old_dentry, - struct inode *new_dir, struct dentry *new_dentry) -{ - if (old_dir != new_dir) - return -EPERM; - - if (new_dentry->d_name[0] == '.') - return -EPERM; - - if (old_dentry->d_name[0] == '.') - return -EPERM; - - return 0; -} - -/* - * Taken from dcache_readdir(). - * This version has a few tweeks to ensure that we always report the - * virtual files and that we don't report them twice. - */ static int dmfs_lv_readdir(struct file *filp, void *dirent, filldir_t filldir) { int i; @@ -143,51 +71,17 @@ static int dmfs_lv_readdir(struct file *filp, void *dirent, filldir_t filldir) filp->f_pos++; /* fallthrough */ case 2: - if (filldir(dirent, ".active", 7, i, 2, DT_REG) < 0) + if (filldir(dirent, "table", 5, i, 2, DT_REG) < 0) break; i++; filp->f_pos++; /* fallthrough */ case 3: - if (filldir(dirent, ".suspend_IO", 11, i, 3, DT_REG) < 0) + if (filldir(dirent, "suspend_IO", 10, i, 3, DT_REG) < 0) break; i++; filp->f_pos++; /* fallthrough */ - default: { - struct list_head *list; - int j = i - 4; - - spin_lock(&dcache_lock); - list = dentry->d_subdirs.next; - - for(;;) { - if (list = &dentry->d_subdirs) { - spin_unlock(&dcache_lock); - return 0; - } - if (!j) - break; - j--; - list = list->next; - } - - while(1) { - struct dentry *de = list_entry(list, struct dentry, d_child); - if (!d_unhashed(de) && de->d_inode && de->d_inode->generic_ip != NULL) { - spin_unlock(&dcache_lock); - if (filldir(dirent, de->d_name.name, de->d_name.len, filp->f_pos, de->d_inode->i_ino, DT_REG) < 0) - break; - spin_lock(&dcache_lock); - } - filp->f_pos++; - list = list->next; - if (list != &dentry->d_subdirs) - continue; - spin_unlock(&dcache_lock); - break; - } - } } return 0; } @@ -205,11 +99,8 @@ static struct dmfs_lv_file_operations = { }; static struct dmfs_lv_inode_operations = { - create: dmfs_lv_create, lookup: dmfs_lv_lookup, - link: dmfs_lv_link, unlink: dmfs_lv_unlink, - rename: dmfs_lv_rename, }; struct inode *dmfs_create_lv(struct inode *dir, struct dentry *dentry, int mode) diff --git a/driver/device-mapper/dmfs-table.c b/driver/device-mapper/dmfs-table.c index 5c1858135..cebb85b1f 100644 --- a/driver/device-mapper/dmfs-table.c +++ b/driver/device-mapper/dmfs-table.c @@ -25,6 +25,18 @@ #include "dm.h" +static inline char *next_token(char **p) +{ + static const char *delim = " \t"; + char *r; + + do { + r = strsep(p, delim); + } while(r && *r == 0); + + return r; +} + static int dmfs_parse_line(struct dmfs_table *t, char *str) { char *p = str; @@ -34,17 +46,17 @@ static int dmfs_parse_line(struct dmfs_table *t, char *str) void *context; struct target_type *ttype; - tok = strsep(&p, delim); + tok = next_token(&p); if (!tok) return -1; start = simple_strtoul(tok, NULL, 10); - tok = strsep(&p, delim); + tok = next_token(&p); if (!tok) return -1; size = simple_strtoul(tok, NULL, 10); - tok = strsep(&p, delim); + tok = next_token(&p); if (!tok) return -1; -- 2.43.5