fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / drivers / oprofile / oprofilefs.c
index ed1efe6..5756401 100644 (file)
@@ -21,7 +21,7 @@
 
 #define OPROFILEFS_MAGIC 0x6f70726f
 
-spinlock_t oprofilefs_lock = SPIN_LOCK_UNLOCKED;
+DEFINE_SPINLOCK(oprofilefs_lock);
 
 static struct inode * oprofilefs_get_inode(struct super_block * sb, int mode)
 {
@@ -31,7 +31,6 @@ static struct inode * oprofilefs_get_inode(struct super_block * sb, int mode)
                inode->i_mode = mode;
                inode->i_uid = 0;
                inode->i_gid = 0;
-               inode->i_blksize = PAGE_CACHE_SIZE;
                inode->i_blocks = 0;
                inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
        }
@@ -45,60 +44,25 @@ static struct super_operations s_ops = {
 };
 
 
-ssize_t oprofilefs_str_to_user(char const * str, char * buf, size_t count, loff_t * offset)
+ssize_t oprofilefs_str_to_user(char const * str, char __user * buf, size_t count, loff_t * offset)
 {
-       size_t len = strlen(str);
-
-       if (!count)
-               return 0;
-
-       if (*offset > len)
-               return 0;
-
-       if (count > len - *offset)
-               count = len - *offset;
-
-       if (copy_to_user(buf, str + *offset, count))
-               return -EFAULT;
-
-       *offset += count;
-
-       return count;
+       return simple_read_from_buffer(buf, count, offset, str, strlen(str));
 }
 
 
 #define TMPBUFSIZE 50
 
-ssize_t oprofilefs_ulong_to_user(unsigned long val, char * buf, size_t count, loff_t * offset)
+ssize_t oprofilefs_ulong_to_user(unsigned long val, char __user * buf, size_t count, loff_t * offset)
 {
        char tmpbuf[TMPBUFSIZE];
-       size_t maxlen;
-
-       if (!count)
-               return 0;
-
-       spin_lock(&oprofilefs_lock);
-       maxlen = snprintf(tmpbuf, TMPBUFSIZE, "%lu\n", val);
-       spin_unlock(&oprofilefs_lock);
+       size_t maxlen = snprintf(tmpbuf, TMPBUFSIZE, "%lu\n", val);
        if (maxlen > TMPBUFSIZE)
                maxlen = TMPBUFSIZE;
-
-       if (*offset > maxlen)
-               return 0;
-
-       if (count > maxlen - *offset)
-               count = maxlen - *offset;
-
-       if (copy_to_user(buf, tmpbuf + *offset, count))
-               return -EFAULT;
-
-       *offset += count;
-
-       return count;
+       return simple_read_from_buffer(buf, count, offset, tmpbuf, maxlen);
 }
 
 
-int oprofilefs_ulong_from_user(unsigned long * val, char const * buf, size_t count)
+int oprofilefs_ulong_from_user(unsigned long * val, char const __user * buf, size_t count)
 {
        char tmpbuf[TMPBUFSIZE];
 
@@ -120,14 +84,14 @@ int oprofilefs_ulong_from_user(unsigned long * val, char const * buf, size_t cou
 }
 
 
-static ssize_t ulong_read_file(struct file * file, char * buf, size_t count, loff_t * offset)
+static ssize_t ulong_read_file(struct file * file, char __user * buf, size_t count, loff_t * offset)
 {
        unsigned long * val = file->private_data;
        return oprofilefs_ulong_to_user(*val, buf, count, offset);
 }
 
 
-static ssize_t ulong_write_file(struct file * file, char const * buf, size_t count, loff_t * offset)
+static ssize_t ulong_write_file(struct file * file, char const __user * buf, size_t count, loff_t * offset)
 {
        unsigned long * value = file->private_data;
        int retval;
@@ -145,8 +109,8 @@ static ssize_t ulong_write_file(struct file * file, char const * buf, size_t cou
 
 static int default_open(struct inode * inode, struct file * filp)
 {
-       if (inode->u.generic_ip)
-               filp->private_data = inode->u.generic_ip;
+       if (inode->i_private)
+               filp->private_data = inode->i_private;
        return 0;
 }
 
@@ -165,21 +129,19 @@ static struct file_operations ulong_ro_fops = {
 
 
 static struct dentry * __oprofilefs_create_file(struct super_block * sb,
-       struct dentry * root, char const * name, struct file_operations * fops)
+       struct dentry * root, char const * name, const struct file_operations * fops,
+       int perm)
 {
        struct dentry * dentry;
        struct inode * inode;
-       struct qstr qname;
-       qname.name = name;
-       qname.len = strlen(name);
-       qname.hash = full_name_hash(qname.name, qname.len);
-       dentry = d_alloc(root, &qname);
+
+       dentry = d_alloc_name(root, name);
        if (!dentry)
-               return 0;
-       inode = oprofilefs_get_inode(sb, S_IFREG | 0644);
+               return NULL;
+       inode = oprofilefs_get_inode(sb, S_IFREG | perm);
        if (!inode) {
                dput(dentry);
-               return 0;
+               return NULL;
        }
        inode->i_fop = fops;
        d_add(dentry, inode);
@@ -190,11 +152,12 @@ static struct dentry * __oprofilefs_create_file(struct super_block * sb,
 int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
        char const * name, unsigned long * val)
 {
-       struct dentry * d = __oprofilefs_create_file(sb, root, name, &ulong_fops);
+       struct dentry * d = __oprofilefs_create_file(sb, root, name,
+                                                    &ulong_fops, 0644);
        if (!d)
                return -EFAULT;
 
-       d->d_inode->u.generic_ip = val;
+       d->d_inode->i_private = val;
        return 0;
 }
 
@@ -202,16 +165,17 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
        char const * name, unsigned long * val)
 {
-       struct dentry * d = __oprofilefs_create_file(sb, root, name, &ulong_ro_fops);
+       struct dentry * d = __oprofilefs_create_file(sb, root, name,
+                                                    &ulong_ro_fops, 0444);
        if (!d)
                return -EFAULT;
 
-       d->d_inode->u.generic_ip = val;
+       d->d_inode->i_private = val;
        return 0;
 }
 
 
-static ssize_t atomic_read_file(struct file * file, char * buf, size_t count, loff_t * offset)
+static ssize_t atomic_read_file(struct file * file, char __user * buf, size_t count, loff_t * offset)
 {
        atomic_t * val = file->private_data;
        return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
@@ -227,19 +191,29 @@ static struct file_operations atomic_ro_fops = {
 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
        char const * name, atomic_t * val)
 {
-       struct dentry * d = __oprofilefs_create_file(sb, root, name, &atomic_ro_fops);
+       struct dentry * d = __oprofilefs_create_file(sb, root, name,
+                                                    &atomic_ro_fops, 0444);
        if (!d)
                return -EFAULT;
 
-       d->d_inode->u.generic_ip = val;
+       d->d_inode->i_private = val;
        return 0;
 }
 
  
 int oprofilefs_create_file(struct super_block * sb, struct dentry * root,
-       char const * name, struct file_operations * fops)
+       char const * name, const struct file_operations * fops)
 {
-       if (!__oprofilefs_create_file(sb, root, name, fops))
+       if (!__oprofilefs_create_file(sb, root, name, fops, 0644))
+               return -EFAULT;
+       return 0;
+}
+
+
+int oprofilefs_create_file_perm(struct super_block * sb, struct dentry * root,
+       char const * name, const struct file_operations * fops, int perm)
+{
+       if (!__oprofilefs_create_file(sb, root, name, fops, perm))
                return -EFAULT;
        return 0;
 }
@@ -250,17 +224,14 @@ struct dentry * oprofilefs_mkdir(struct super_block * sb,
 {
        struct dentry * dentry;
        struct inode * inode;
-       struct qstr qname;
-       qname.name = name;
-       qname.len = strlen(name);
-       qname.hash = full_name_hash(qname.name, qname.len);
-       dentry = d_alloc(root, &qname);
+
+       dentry = d_alloc_name(root, name);
        if (!dentry)
-               return 0;
+               return NULL;
        inode = oprofilefs_get_inode(sb, S_IFDIR | 0755);
        if (!inode) {
                dput(dentry);
-               return 0;
+               return NULL;
        }
        inode->i_op = &simple_dir_inode_operations;
        inode->i_fop = &simple_dir_operations;
@@ -278,6 +249,7 @@ static int oprofilefs_fill_super(struct super_block * sb, void * data, int silen
        sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
        sb->s_magic = OPROFILEFS_MAGIC;
        sb->s_op = &s_ops;
+       sb->s_time_gran = 1;
 
        root_inode = oprofilefs_get_inode(sb, S_IFDIR | 0755);
        if (!root_inode)
@@ -299,10 +271,10 @@ static int oprofilefs_fill_super(struct super_block * sb, void * data, int silen
 }
 
 
-static struct super_block *oprofilefs_get_sb(struct file_system_type *fs_type,
-       int flags, const char *dev_name, void *data)
+static int oprofilefs_get_sb(struct file_system_type *fs_type,
+       int flags, const char *dev_name, void *data, struct vfsmount *mnt)
 {
-       return get_sb_single(fs_type, flags, data, oprofilefs_fill_super);
+       return get_sb_single(fs_type, flags, data, oprofilefs_fill_super, mnt);
 }