x86: early memtest to find bad ram
[sfrench/cifs-2.6.git] / fs / libfs.c
index f2b32d3a9093a58eba69fabdbbbf0bf5ea1ae7a3..b004dfadd8917d4cbf91d9994a9b4893ea6b3922 100644 (file)
@@ -8,6 +8,7 @@
 #include <linux/mount.h>
 #include <linux/vfs.h>
 #include <linux/mutex.h>
+#include <linux/exportfs.h>
 
 #include <asm/uaccess.h>
 
@@ -340,13 +341,10 @@ int simple_prepare_write(struct file *file, struct page *page,
                        unsigned from, unsigned to)
 {
        if (!PageUptodate(page)) {
-               if (to - from != PAGE_CACHE_SIZE) {
-                       void *kaddr = kmap_atomic(page, KM_USER0);
-                       memset(kaddr, 0, from);
-                       memset(kaddr + to, 0, PAGE_CACHE_SIZE - to);
-                       flush_dcache_page(page);
-                       kunmap_atomic(kaddr, KM_USER0);
-               }
+               if (to - from != PAGE_CACHE_SIZE)
+                       zero_user_segments(page,
+                               0, from,
+                               to, PAGE_CACHE_SIZE);
        }
        return 0;
 }
@@ -371,8 +369,8 @@ int simple_write_begin(struct file *file, struct address_space *mapping,
        return simple_prepare_write(file, page, from, from+len);
 }
 
-int simple_commit_write(struct file *file, struct page *page,
-                       unsigned from, unsigned to)
+static int simple_commit_write(struct file *file, struct page *page,
+                              unsigned from, unsigned to)
 {
        struct inode *inode = page->mapping->host;
        loff_t pos = ((loff_t)page->index << PAGE_CACHE_SHIFT) + to;
@@ -585,8 +583,8 @@ int simple_transaction_release(struct inode *inode, struct file *file)
 /* Simple attribute files */
 
 struct simple_attr {
-       u64 (*get)(void *);
-       void (*set)(void *, u64);
+       int (*get)(void *, u64 *);
+       int (*set)(void *, u64);
        char get_buf[24];       /* enough to store a u64 and "\n\0" */
        char set_buf[24];
        void *data;
@@ -597,7 +595,7 @@ struct simple_attr {
 /* simple_attr_open is called by an actual attribute open file operation
  * to set the attribute specific access operations. */
 int simple_attr_open(struct inode *inode, struct file *file,
-                    u64 (*get)(void *), void (*set)(void *, u64),
+                    int (*get)(void *, u64 *), int (*set)(void *, u64),
                     const char *fmt)
 {
        struct simple_attr *attr;
@@ -617,7 +615,7 @@ int simple_attr_open(struct inode *inode, struct file *file,
        return nonseekable_open(inode, file);
 }
 
-int simple_attr_close(struct inode *inode, struct file *file)
+int simple_attr_release(struct inode *inode, struct file *file)
 {
        kfree(file->private_data);
        return 0;
@@ -636,15 +634,24 @@ ssize_t simple_attr_read(struct file *file, char __user *buf,
        if (!attr->get)
                return -EACCES;
 
-       mutex_lock(&attr->mutex);
-       if (*ppos) /* continued read */
+       ret = mutex_lock_interruptible(&attr->mutex);
+       if (ret)
+               return ret;
+
+       if (*ppos) {            /* continued read */
                size = strlen(attr->get_buf);
-       else      /* first read */
+       } else {                /* first read */
+               u64 val;
+               ret = attr->get(attr->data, &val);
+               if (ret)
+                       goto out;
+
                size = scnprintf(attr->get_buf, sizeof(attr->get_buf),
-                                attr->fmt,
-                                (unsigned long long)attr->get(attr->data));
+                                attr->fmt, (unsigned long long)val);
+       }
 
        ret = simple_read_from_buffer(buf, len, ppos, attr->get_buf, size);
+out:
        mutex_unlock(&attr->mutex);
        return ret;
 }
@@ -659,11 +666,13 @@ ssize_t simple_attr_write(struct file *file, const char __user *buf,
        ssize_t ret;
 
        attr = file->private_data;
-
        if (!attr->set)
                return -EACCES;
 
-       mutex_lock(&attr->mutex);
+       ret = mutex_lock_interruptible(&attr->mutex);
+       if (ret)
+               return ret;
+
        ret = -EFAULT;
        size = min(sizeof(attr->set_buf) - 1, len);
        if (copy_from_user(attr->set_buf, buf, size))
@@ -678,6 +687,93 @@ out:
        return ret;
 }
 
+/*
+ * This is what d_alloc_anon should have been.  Once the exportfs
+ * argument transition has been finished I will update d_alloc_anon
+ * to this prototype and this wrapper will go away.   --hch
+ */
+static struct dentry *exportfs_d_alloc(struct inode *inode)
+{
+       struct dentry *dentry;
+
+       if (!inode)
+               return NULL;
+       if (IS_ERR(inode))
+               return ERR_PTR(PTR_ERR(inode));
+
+       dentry = d_alloc_anon(inode);
+       if (!dentry) {
+               iput(inode);
+               dentry = ERR_PTR(-ENOMEM);
+       }
+       return dentry;
+}
+
+/**
+ * generic_fh_to_dentry - generic helper for the fh_to_dentry export operation
+ * @sb:                filesystem to do the file handle conversion on
+ * @fid:       file handle to convert
+ * @fh_len:    length of the file handle in bytes
+ * @fh_type:   type of file handle
+ * @get_inode: filesystem callback to retrieve inode
+ *
+ * This function decodes @fid as long as it has one of the well-known
+ * Linux filehandle types and calls @get_inode on it to retrieve the
+ * inode for the object specified in the file handle.
+ */
+struct dentry *generic_fh_to_dentry(struct super_block *sb, struct fid *fid,
+               int fh_len, int fh_type, struct inode *(*get_inode)
+                       (struct super_block *sb, u64 ino, u32 gen))
+{
+       struct inode *inode = NULL;
+
+       if (fh_len < 2)
+               return NULL;
+
+       switch (fh_type) {
+       case FILEID_INO32_GEN:
+       case FILEID_INO32_GEN_PARENT:
+               inode = get_inode(sb, fid->i32.ino, fid->i32.gen);
+               break;
+       }
+
+       return exportfs_d_alloc(inode);
+}
+EXPORT_SYMBOL_GPL(generic_fh_to_dentry);
+
+/**
+ * generic_fh_to_dentry - generic helper for the fh_to_parent export operation
+ * @sb:                filesystem to do the file handle conversion on
+ * @fid:       file handle to convert
+ * @fh_len:    length of the file handle in bytes
+ * @fh_type:   type of file handle
+ * @get_inode: filesystem callback to retrieve inode
+ *
+ * This function decodes @fid as long as it has one of the well-known
+ * Linux filehandle types and calls @get_inode on it to retrieve the
+ * inode for the _parent_ object specified in the file handle if it
+ * is specified in the file handle, or NULL otherwise.
+ */
+struct dentry *generic_fh_to_parent(struct super_block *sb, struct fid *fid,
+               int fh_len, int fh_type, struct inode *(*get_inode)
+                       (struct super_block *sb, u64 ino, u32 gen))
+{
+       struct inode *inode = NULL;
+
+       if (fh_len <= 2)
+               return NULL;
+
+       switch (fh_type) {
+       case FILEID_INO32_GEN_PARENT:
+               inode = get_inode(sb, fid->i32.parent_ino,
+                                 (fh_len > 3 ? fid->i32.parent_gen : 0));
+               break;
+       }
+
+       return exportfs_d_alloc(inode);
+}
+EXPORT_SYMBOL_GPL(generic_fh_to_parent);
+
 EXPORT_SYMBOL(dcache_dir_close);
 EXPORT_SYMBOL(dcache_dir_lseek);
 EXPORT_SYMBOL(dcache_dir_open);
@@ -686,7 +782,6 @@ EXPORT_SYMBOL(generic_read_dir);
 EXPORT_SYMBOL(get_sb_pseudo);
 EXPORT_SYMBOL(simple_write_begin);
 EXPORT_SYMBOL(simple_write_end);
-EXPORT_SYMBOL(simple_commit_write);
 EXPORT_SYMBOL(simple_dir_inode_operations);
 EXPORT_SYMBOL(simple_dir_operations);
 EXPORT_SYMBOL(simple_empty);
@@ -709,6 +804,6 @@ EXPORT_SYMBOL(simple_transaction_get);
 EXPORT_SYMBOL(simple_transaction_read);
 EXPORT_SYMBOL(simple_transaction_release);
 EXPORT_SYMBOL_GPL(simple_attr_open);
-EXPORT_SYMBOL_GPL(simple_attr_close);
+EXPORT_SYMBOL_GPL(simple_attr_release);
 EXPORT_SYMBOL_GPL(simple_attr_read);
 EXPORT_SYMBOL_GPL(simple_attr_write);