1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-10-27 10:25:13 +03:00

o Beginnings of new interface.

This commit is contained in:
Steven Whitehouse 2001-09-26 08:06:46 +00:00
parent 0153e94a50
commit d91ed719e9
4 changed files with 349 additions and 93 deletions

View File

@ -1,5 +1,5 @@
/*
* dmfs-suspend.c
* dmfs-error.c
*
* Copyright (C) 2001 Sistina Software
*
@ -22,60 +22,34 @@
#include <linux/config.h>
#include <linux/fs.h>
static ssize_t dmfs_suspend_read(struct file *file, char *buf, size_t size, loff_t *pos)
static ssize_t dmfs_error_read(struct file *file, char *buf, size_t size, loff_t *pos)
{
struct inode *inode = file->f_dentry->d_parent->d_inode;
struct mapped_device *md = (struct mapped_device *)inode->u.generic_ip;
char content[2] = { '0', '\n' };
if (size > 2)
size = 2;
if (test_bit(DM_ACTIVE, &md->state))
content[0] = '1';
if (copy_to_user(buf, content, size))
return -EFAULT;
return size;
}
static ssize_t dmfs_suspend_write(struct file *file, const char *buf, size_t size, loff_t *pos)
static ssize_t dmfs_error_write(struct file *file, const char *buf, size_t size, loff_t *pos)
{
struct inode *inode = file->f_dentry->d_inode;
char cmd;
if (size == 0)
return 0;
size = 1;
if (copy_from_user(&cmd, buf, size))
return -EFAULT;
if (cmd != '0' && cmd != '1')
return -EINVAL;
/* do suspend or unsuspend */
return size;
}
static int dmfs_suspend_sync(struct file *file, struct dentry *dentry, int datasync)
static int dmfs_error_sync(struct file *file, struct dentry *dentry, int datasync)
{
return 0;
}
static struct dm_table_file_operations = {
read: dmfs_suspend_read,
write: dmfs_suspend_write,
fsync: dmfs_suspend_sync,
read: dmfs_error_read,
write: dmfs_error_write,
fsync: dmfs_error_sync,
};
static struct dmfs_suspend_inode_operations = {
static struct dmfs_error_inode_operations = {
};
int dmfs_create_suspend(struct inode *dir, int mode)
int dmfs_create_error(struct inode *dir, int mode)
{
struct inode *inode = new_inode(dir->i_sb);
@ -87,8 +61,8 @@ int dmfs_create_suspend(struct inode *dir, int mode)
inode->i_blocks = 0;
inode->i_rdev = NODEV;
inode->i_atime = inode->i_ctime = inode->i_mtime = CURRENT_TIME;
inode->i_fop = &dmfs_suspend_file_operations;
inode->i_op = &dmfs_suspend_inode_operations;
inode->i_fop = &dmfs_error_file_operations;
inode->i_op = &dmfs_error_inode_operations;
}
return inode;

View File

@ -22,88 +22,167 @@
/* Heavily based upon ramfs */
#include <linux/config.h>
#include <linux/ctype.h>
#include <linux/fs.h>
static int dmfs_lv_unlink(struct inode *dir, struct dentry *dentry)
static int is_identifier(const char *str, int len)
{
inode->i_nlink--;
dput(dentry);
return 0;
while(len--) {
if (!isalnum(*str) && *str != '_')
return 0;
str++;
}
return 1;
}
static int dmfs_lv_mkdir(struct inode *dir, struct dentry *dentry, int mode)
{
struct super_block *sb = dir->i_sb;
struct inode *inode;
struct mapped_device *md;
if (dentry->d_name.len >= DM_NAME_LEN)
return -EINVAL;
if (!is_identifier(name, dentry->d_name.len))
return -EPERM;
if (dentry->d_name.len == 6 && memcmp(dentry->d_name.name, "ACTIVE", 6) == 0)
return -EINVAL;
if (dentry->d_name[0] == '.')
return -EINVAL;
inode = dmfs_create_lv(dir, dentry, mode);
if (!IS_ERR(inode)) {
md = dm_create(name, -1);
if (!IS_ERR(md)) {
inode->u.generic_ip = md;
md->inode = inode;
d_instantiate(dentry, inode);
dget(dentry);
return 0;
}
iput(inode);
return PTR_ERR(md);
}
return PTR_ERR(inode);
}
/*
* if u.generic_ip is not NULL, then it indicates an inode which
* represents a table. If it is NULL then the inode is a virtual
* file and should be deleted along with the directory.
*/
static inline positive(struct dentry *dentry)
{
return dentry->d_inode && dentry->d_inode->u.generic_ip &&
!d_unhashed(dentry);
}
static int empty(struct dentry *dentry)
{
struct list_head *list;
spin_lock(&dcache_lock);
list = dentry->d_subdirs.next;
while(list != &dentry->d_subdirs) {
struct dentry *de = list_entry(list, struct dentry, d_child);
if (positive(de)) {
spin_unlock(&dcache_lock);
return 0;
}
list = list->next;
}
spin_unlock(&dcache_lock);
return 1;
}
static int dmfs_delete_virtual(struct inode *dir, struct dentry *dentry)
{
struct list_head *list;
struct dentry *de;
int rv = 0;
while(1) {
spin_lock(&dcache_lock);
list = dentry->d_subdirs.next;
if (list == &dentry->d_subdirs) {
spin_unlock(&dcache_lock);
break;
}
de = list_entry(list, struct dentry, d_child);
if (de->d_inode && !d_unhashed(de)) {
spin_unlock(&dcache_lock);
if (de->d_inode->u.generic_ip)
BUG();
rv = de->d_inode->ops->unlink(dir, de);
if (rv == 0) {
d_delete(de);
continue;
}
break;
}
spin_unlock(&dcache_lock);
}
return rv;
}
static int dmfs_lv_rmdir(struct inode *dir, struct dentry *dentry)
{
int ret = -ENOTEMPTY;
if (empty(dentry)) {
struct inode *inode = dentry->d_inode;
ret = dmfs_delete_virtual(dir, dentry);
if (ret == 0) {
inode->i_nlink--;
dput(dentry);
}
}
return ret;
}
static struct dentry *dmfs_lv_lookup(struct inode *dir, struct dentry *dentry)
{
struct inode *inode = NULL;
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);
d_add(dentry, NULL);
return NULL;
}
static int dmfs_lv_readdir(struct file *filp, void *dirent, filldir_t filldir)
static int dmfs_lv_rename(struct inode *old_dir, struct dentry *old_dentry,
struct inode *new_dir, struct dentry *new_dentry)
{
int i;
struct dentry *dentry = filp->f_dentry;
/* Can only rename - not move between directories! */
if (old_dir != new_dir)
return -EPERM;
i = flip->f_pos;
switch(i) {
case 0:
if (filldir(dirent, ".", 1, i, dentry->d_inode->i_ino, DT_DIR) < 0)
break;
i++;
flip->f_pos++;
/* fallthrough */
case 1:
if (filldir(dirent, "..", 2, i, dentry->d_parent->d_inode->i_ino, DT_DIR) < 0
break;
i++;
filp->f_pos++;
/* fallthrough */
case 2:
if (filldir(dirent, "table", 5, i, 2, DT_REG) < 0)
break;
i++;
filp->f_pos++;
/* fallthrough */
case 3:
if (filldir(dirent, "suspend_IO", 10, i, 3, DT_REG) < 0)
break;
i++;
filp->f_pos++;
/* fallthrough */
}
return 0;
return -EINVAL; /* FIXME: a change of LV name here */
}
static int dmfs_lv_sync(struct file *file, struct dentry *dentry, int datasync)
{
return 0;
}
static struct dmfs_lv_file_operations = {
static struct dm_root_file_operations = {
read: generic_read_dir,
readdir: dmfs_lv_readdir,
readdir: dcache_readdir,
fsync: dmfs_lv_sync,
};
static struct dmfs_lv_inode_operations = {
static struct dm_root_inode_operations = {
lookup: dmfs_lv_lookup,
unlink: dmfs_lv_unlink,
mkdir: dmfs_lv_mkdir,
rmdir: dmfs_lv_rmdir,
rename: dmfs_lv_rename,
};
struct inode *dmfs_create_lv(struct inode *dir, struct dentry *dentry, int mode)
struct inode *dmfs_create_lv(struct super_block *sb, int mode)
{
struct inode *inode = new_inode(sb);

View File

@ -0,0 +1,67 @@
/*
* dmfs-status.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 <linux/config.h>
#include <linux/fs.h>
static ssize_t dmfs_status_read(struct file *file, char *buf, size_t size, loff_t *pos)
{
return size;
}
static ssize_t dmfs_status_write(struct file *file, const char *buf, size_t size, loff_t *pos)
{
return size;
}
static int dmfs_status_sync(struct file *file, struct dentry *dentry, int datasync)
{
return 0;
}
static struct dm_table_file_operations = {
read: dmfs_status_read,
write: dmfs_status_write,
fsync: dmfs_status_sync,
};
static struct dmfs_status_inode_operations = {
};
int dmfs_create_status(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_status_file_operations;
inode->i_op = &dmfs_status_inode_operations;
}
return inode;
}

View File

@ -0,0 +1,136 @@
/*
* dmfs-tdir.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.
*/
/* Heavily based upon ramfs */
#include <linux/config.h>
#include <linux/fs.h>
extern struct inode *dmfs_create_error(struct inode *, int);
extern struct inode *dmfs_create_table(struct inode *, int);
extern struct inode *dmfs_create_status(struct inode *, int);
static int dmfs_tdir_unlink(struct inode *dir, struct dentry *dentry)
{
inode->i_nlink--;
dput(dentry);
return 0;
}
static struct dentry *dmfs_tdir_lookup(struct inode *dir, struct dentry *dentry)
{
struct inode *inode = NULL;
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);
if (memcmp("error", name, 5) == 0)
inode = dmfs_create_error(dir, 0600);
break;
case 6:
if (memcmp("status", name, 6) == 0)
inode = dmfs_create_status(dir, 0600);
break;
}
d_add(dentry, inode);
return NULL;
}
static int dmfs_tdir_readdir(struct file *filp, void *dirent, filldir_t filldir)
{
int i;
struct dentry *dentry = filp->f_dentry;
i = flip->f_pos;
switch(i) {
case 0:
if (filldir(dirent, ".", 1, i, dentry->d_inode->i_ino, DT_DIR) < 0)
break;
i++;
flip->f_pos++;
/* fallthrough */
case 1:
if (filldir(dirent, "..", 2, i, dentry->d_parent->d_inode->i_ino, DT_DIR) < 0
break;
i++;
filp->f_pos++;
/* fallthrough */
case 2:
if (filldir(dirent, "table", 5, i, 2, DT_REG) < 0)
break;
i++;
filp->f_pos++;
/* fallthrough */
case 3:
if (filldir(dirent, "error", 5, i, 3, DT_REG) < 0)
break;
i++;
filp->f_pos++;
/* fallthrough */
case 4:
if (filldir(dirent, "status", 6, i, 4, DT_REG) < 0)
break;
i++;
filp->f_pos++;
}
return 0;
}
static int dmfs_tdir_sync(struct file *file, struct dentry *dentry, int datasync)
{
return 0;
}
static struct dmfs_tdir_file_operations = {
read: generic_read_dir,
readdir: dmfs_tdir_readdir,
fsync: dmfs_tdir_sync,
};
static struct dmfs_tdir_inode_operations = {
lookup: dmfs_tdir_lookup,
unlink: dmfs_tdir_unlink,
};
struct inode *dmfs_create_tdir(struct inode *dir, struct dentry *dentry, int mode)
{
struct inode *inode = new_inode(sb);
if (inode) {
inode->i_mode = mode | S_IFDIR;
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_tdir_file_operations;
inode->i_op = &dmfs_tdir_dir_operations;
}
return inode;
}