PATCH: Arla 0.90 on Linux 2.6.24-2.6.35-rc1

Bo Brantén bosse at acc.umu.se
Sun Jul 11 18:58:19 CEST 2010


fix for leak in a reference count

Bo Branten
-------------- next part --------------
diff -uprN arla-0.90/nnpfs/linux/nnpfs_blocks.c arla-0.90-new/nnpfs/linux/nnpfs_blocks.c
--- arla-0.90/nnpfs/linux/nnpfs_blocks.c	2007-01-08 14:24:24.000000000 +0100
+++ arla-0.90-new/nnpfs/linux/nnpfs_blocks.c	2010-07-11 17:18:26.572458961 +0200
@@ -34,7 +34,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-/* $Id: nnpfs_blocks.c,v 1.3 2007/01/08 13:24:24 tol Exp $ */
+/* $Id: nnpfs_blocks.c,v 1.4 2008/03/08 21:38:16 tol Exp $ */
 
 #include <nnpfs/nnpfs_locl.h>
 #include <nnpfs/nnpfs_fs.h>
@@ -302,6 +302,24 @@ nnpfs_block_extend(struct nnpfs_node *no
     return ret;
 }
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 23)
+/*
+ * Helper to emulate vfs_path_lookup() on linux < 2.6.23
+ */
+static int
+vfs_path_lookup(struct dentry *dentry, struct vfsmount *mnt,
+		const char *cachename, unsigned int flags,
+		struct nameidata *nd)
+{
+    nd->dentry = dget(dentry);
+    nd->mnt = mntget(mnt);
+    nd->last_type = LAST_ROOT;
+    nd->depth = 0;
+    nd->flags = flags;
+    return path_walk(cachename, nd);
+}
+#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 23) */
+
 /*
  * open indicated cache block file. needs to be closed by caller.
  *
@@ -322,6 +340,10 @@ nnpfs_block_open(struct nnpfs_node *node
     uid_t saveuid;
     gid_t savegid;
     int ret;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29)
+    const struct cred *old_cred;
+    struct cred *override_cred;
+#endif
 
     BUG_ON(!nnpfsp);
     BUG_ON(flags & O_CREAT && file != NULL);
@@ -346,21 +368,26 @@ nnpfs_block_open(struct nnpfs_node *node
     BUG_ON(!nnpfsp->cachedir || !nnpfsp->cacheroot);
     
     /* use the nfsd trick to give us access */
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,28)
     saveuid = current->fsuid;
     savegid = current->fsgid;
     current->fsuid = nnpfsp->uid;
     current->fsgid = nnpfsp->gid;
-
-    nd.dentry = dget(nnpfsp->cachedir);
-    nd.mnt = mntget(nnpfsp->cacheroot);
-    nd.last_type = LAST_NORM;
-    nd.depth = 0;
-    nd.flags = 0;
-    
-    if (flags & O_CREAT)
-	nd.flags = LOOKUP_PARENT;
-    
-    ret = path_walk(cachename, &nd);
+#else
+    saveuid = current_fsuid();
+    savegid = current_fsgid();
+    override_cred = prepare_creds();
+    if (!override_cred)
+        return -ENOMEM;
+    override_cred->fsuid = nnpfsp->uid;
+    override_cred->fsgid = nnpfsp->gid;
+    old_cred = override_creds(override_cred);
+#endif
+
+    ret = vfs_path_lookup(nnpfsp->cachedir, nnpfsp->cacheroot,
+			  cachename,
+			  flags & O_CREAT ? LOOKUP_PARENT : 0,
+			  &nd);
     if (ret) {
 	uint32_t nmasks = node->data.nmasks;
 	uint32_t mask;
@@ -391,12 +418,21 @@ nnpfs_block_open(struct nnpfs_node *node
 	if (IS_ERR(dentry)) {
 	    ret = PTR_ERR(dentry);
 	} else {
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)
 	    ret = vfs_create(nd.dentry->d_inode, dentry, S_IRUSR|S_IWUSR, &nd);
+#else
+	    ret = vfs_create(nd.path.dentry->d_inode, dentry, S_IRUSR|S_IWUSR, &nd);
+#endif
 	    dput(dentry);
 	}
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)
 	mutex_unlock(&nd.dentry->d_inode->i_mutex);
 	path_release(&nd);
+#else
+	mutex_unlock(&nd.path.dentry->d_inode->i_mutex);
+	path_put(&nd.path);
+#endif
 
 	if (ret) {
 	    printk("nnpfs_block_open(%s) create failed: %d\n", cachename, -ret);
@@ -410,12 +446,22 @@ nnpfs_block_open(struct nnpfs_node *node
 	    ret = nnpfs_block_extend(node, offset);
 	}
     } else {
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)
 	struct file *f = dentry_open(nd.dentry, nd.mnt, flags);
+#elif LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29)
+	struct file *f = dentry_open(nd.path.dentry, nd.path.mnt, flags);
+#else
+        struct file *f = dentry_open(nd.path.dentry, nd.path.mnt, flags, current_cred());
+#endif
 	if (IS_ERR(f)) {
 	    ret = PTR_ERR(f);
 	    printk("nnpfs_block_open(%s) open failed: %d\n", cachename, -ret);
 	    nnpfs_debug_oops();
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)
 	    path_release(&nd);
+#else
+	    path_put(&nd.path);
+#endif
 	} else {
 	    *file = f;
 	}
@@ -424,8 +470,13 @@ nnpfs_block_open(struct nnpfs_node *node
     /* path_release() is usually handled on close */
 
  out:
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,28)
     current->fsuid = saveuid;
     current->fsgid = savegid;
+#else
+    revert_creds(old_cred);
+    put_cred(override_cred);
+#endif
 
     return ret;
 }
diff -uprN arla-0.90/nnpfs/linux/nnpfs_inodeops.c arla-0.90-new/nnpfs/linux/nnpfs_inodeops.c
--- arla-0.90/nnpfs/linux/nnpfs_inodeops.c	2006-12-11 17:35:26.000000000 +0100
+++ arla-0.90-new/nnpfs/linux/nnpfs_inodeops.c	2010-07-11 17:18:26.572458961 +0200
@@ -48,7 +48,7 @@
 #include <asm/fcntl.h>
 
 #ifdef RCSID
-RCSID("$Id: nnpfs_inodeops.c,v 1.223 2006/12/11 16:35:26 tol Exp $");
+RCSID("$Id: nnpfs_inodeops.c,v 1.224 2008/03/08 21:40:10 tol Exp $");
 #endif
 
 static int
@@ -105,7 +105,11 @@ nnpfs_vma_close (struct vm_area_struct *
 }
 
 static struct vm_operations_struct nnpfs_file_vm_ops = {
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 23)
     .nopage	= filemap_nopage,
+#else
+    .fault      = filemap_fault,
+#endif
     .close	= nnpfs_vma_close,
 };
 
@@ -134,12 +138,14 @@ nnpfs_print_path(struct dentry *dentry)
  *
  */
 
+#if 0
 void
 nnpfs_print_lock(char *s, struct semaphore *sem)
 {
     NNPFSDEB(XDEBLOCK, ("lock: %s sem: %p count: %d\n",
 		      s, sem, (int)atomic_read(&sem->count)));
 }
+#endif
 
 /*
  *
@@ -240,7 +246,11 @@ nnpfs_lookup (struct inode *dir, struct 
 
 	msg.header.opcode = NNPFS_MSG_GETNODE;
         
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,28)
 	msg.cred.uid = current->uid;
+#else
+        msg.cred.uid = current_uid();
+#endif
 	msg.cred.pag = nnpfs_get_pag();
 	msg.parent_handle = d->handle;
         
@@ -310,7 +320,11 @@ nnpfs_open_valid(struct inode *vp, u_int
       {
 	struct nnpfs_message_open msg;
 	msg.header.opcode = NNPFS_MSG_OPEN;
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,28)
 	msg.cred.uid = current->uid;
+#else
+        msg.cred.uid = current_uid();
+#endif
 	msg.cred.pag = nnpfs_get_pag();
 	msg.handle = xn->handle;
 	msg.tokens = tok;
@@ -425,7 +439,11 @@ nnpfs_fsync_int(struct file *file, u_int
 
 	msg.header.opcode = NNPFS_MSG_PUTDATA;
 	msg.cred.pag = nnpfs_get_pag();
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,28)
 	msg.cred.uid = current->uid;
+#else
+        msg.cred.uid = current_uid();
+#endif
 	msg.handle = xn->handle;
 	msg.flag   = flag;
 	msg.offset = off;
@@ -460,9 +478,17 @@ nnpfs_fsync_int(struct file *file, u_int
  *
  */
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 35)
 static int
 nnpfs_fsync(struct file *file, struct dentry *dentry, int datasync)
+#else
+static int
+nnpfs_fsync(struct file *file, int datasync)
+#endif
 {
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 35)
+    struct dentry *dentry = file->f_path.dentry;
+#endif
     struct inode *inode = DENTRY_TO_INODE(dentry);
     struct nnpfs *nnpfsp;
     struct nnpfs_node *xn;
@@ -511,7 +537,11 @@ nnpfs_attr_valid(struct inode * vp, u_in
             struct nnpfs_message_getattr msg;
 
             msg.header.opcode = NNPFS_MSG_GETATTR;
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,28)
             msg.cred.uid = current->uid;
+#else
+            msg.cred.uid = current_uid();
+#endif
             msg.cred.pag = pag;
             msg.handle = xn->handle;
             error = nnpfs_message_rpc(nnpfsp, &msg.header, sizeof(msg));
@@ -551,7 +581,11 @@ nnpfs_rights_valid(struct inode * vp, nn
             struct nnpfs_message_getattr msg;
 
             msg.header.opcode = NNPFS_MSG_GETATTR;
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,28)
             msg.cred.uid = current->uid;
+#else
+            msg.cred.uid = current_uid();
+#endif
             msg.cred.pag = pag;
             msg.handle = xn->handle;
             error = nnpfs_message_rpc(nnpfsp, &msg.header, sizeof(msg));
@@ -592,8 +626,13 @@ check_rights (nnpfs_rights rights, int m
  * We don't hold i_mutex.
  */
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
 static int
 nnpfs_permission(struct inode *inode, int mode, struct nameidata *nd)
+#else
+static int
+nnpfs_permission(struct inode *inode, int mode)
+#endif
 {
     int error = 0;
     nnpfs_pag_t pag = nnpfs_get_pag();
@@ -636,7 +675,11 @@ nnpfs_do_getdata(struct nnpfs_node *xn, 
     int error;
 
     msg.header.opcode = NNPFS_MSG_GETDATA;
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,28)
     msg.cred.uid = current->uid;
+#else
+    msg.cred.uid = current_uid();
+#endif
     msg.cred.pag = nnpfs_get_pag();
     msg.handle = xn->handle;
     msg.tokens = tok;
@@ -903,9 +946,17 @@ nnpfs_create(struct inode *dir, struct d
     XA_CLEAR(&msg.attr);
     XA_SET_MODE(&msg.attr, mode);
     XA_SET_TYPE(&msg.attr, NNPFS_FILE_REG);
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,28)
     XA_SET_GID(&msg.attr, current->fsgid);
+#else
+    XA_SET_GID(&msg.attr, current_fsgid());
+#endif
     msg.mode = 0;		/* XXX */
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,28)
     msg.cred.uid = current->uid;
+#else
+    msg.cred.uid = current_uid();
+#endif
     msg.cred.pag = nnpfs_get_pag();
     error = nnpfs_message_rpc(nnpfsp, &msg.header, sizeof(msg));
     if (error == 0)
@@ -946,7 +997,11 @@ nnpfs_unlink (struct inode * dir, struct
     if (strlcpy(msg.name, dentry->d_name.name, sizeof(msg.name)) >= NNPFS_MAX_NAME)
 	return -ENAMETOOLONG;
 
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,28)
     msg.cred.uid = current->uid;
+#else
+    msg.cred.uid = current_uid();
+#endif
     msg.cred.pag = nnpfs_get_pag();
     error = nnpfs_message_rpc(nnpfsp, &msg.header, sizeof(msg));
     if (error == 0)
@@ -991,7 +1046,11 @@ nnpfs_rename (struct inode * old_dir, st
     if (strlcpy(msg.new_name, new_dentry->d_name.name, sizeof(msg.new_name)) >= NNPFS_MAX_NAME)
 	return -ENAMETOOLONG;
 	
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,28)
     msg.cred.uid = current->uid;
+#else
+    msg.cred.uid = current_uid();
+#endif
     msg.cred.pag = nnpfs_get_pag();
     error = nnpfs_message_rpc(nnpfsp, &msg.header, sizeof(msg));
     if (error == 0)
@@ -1040,9 +1099,17 @@ nnpfs_mkdir(struct inode * dir, struct d
 	XA_CLEAR(&msg.attr);
 	XA_SET_MODE(&msg.attr, mode);
 	XA_SET_TYPE(&msg.attr, NNPFS_FILE_DIR);
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,28)
 	XA_SET_GID(&msg.attr, current->fsgid);
+#else
+        XA_SET_GID(&msg.attr, current_fsgid());
+#endif
 
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,28)
 	msg.cred.uid = current->uid;
+#else
+        msg.cred.uid = current_uid();
+#endif
 	msg.cred.pag = nnpfs_get_pag();
 	error = nnpfs_message_rpc(nnpfsp, &msg.header, sizeof(msg));
 	if (error == 0)
@@ -1083,7 +1150,11 @@ nnpfs_rmdir(struct inode * dir, struct d
     msg.parent_handle = xn->handle;
     if (strlcpy(msg.name, dentry->d_name.name, sizeof(msg.name)) >= NNPFS_MAX_NAME)
 	    return -ENAMETOOLONG;
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,28)
     msg.cred.uid = current->uid;
+#else
+    msg.cred.uid = current_uid();
+#endif
     msg.cred.pag = nnpfs_get_pag();
     error = nnpfs_message_rpc(nnpfsp, &msg.header, sizeof(msg));
     if (error == 0)
@@ -1128,7 +1199,11 @@ static int nnpfs_link(struct dentry *old
 	if (strlcpy(msg.name, name, sizeof(msg.name)) >= NNPFS_MAX_NAME)
 	    return -ENAMETOOLONG;
 
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,28)
 	msg.cred.uid = current->uid;
+#else
+        msg.cred.uid = current_uid();
+#endif
 	msg.cred.pag = nnpfs_get_pag();
 	error = nnpfs_message_rpc(nnpfsp, &msg.header, sizeof(msg));
 	if (error == 0)
@@ -1157,29 +1232,47 @@ static int nnpfs_symlink(struct inode *d
     xn = VNODE_TO_XNODE(dir);
 
     {
-	struct nnpfs_message_symlink msg;
+	struct nnpfs_message_symlink *msg = NULL;
 
-	msg.header.opcode = NNPFS_MSG_SYMLINK;
-	msg.parent_handle = xn->handle;
-	if (strlcpy(msg.name, name, sizeof(msg.name)) >= NNPFS_MAX_NAME)
-	    return -ENAMETOOLONG;
-	if (strlcpy(msg.contents, symname, sizeof(msg.contents)) >= NNPFS_MAX_SYMLINK_CONTENT)
-	    return -ENAMETOOLONG;
-	XA_CLEAR(&msg.attr);
-	XA_SET_MODE(&msg.attr, 0777);
-	XA_SET_TYPE(&msg.attr, NNPFS_FILE_LNK);
-	XA_SET_GID(&msg.attr, current->fsgid);
+	msg = kmalloc(sizeof(struct nnpfs_message_symlink), GFP_KERNEL);
 
-	msg.cred.uid = current->uid;
-	msg.cred.pag = nnpfs_get_pag();
-	error = nnpfs_message_rpc(nnpfsp, &msg.header, sizeof(msg));
+	if (!msg)
+	  return -ENOMEM;
+
+	msg->header.opcode = NNPFS_MSG_SYMLINK;
+	msg->parent_handle = xn->handle;
+	if (strlcpy(msg->name, name, sizeof(msg->name)) >= NNPFS_MAX_NAME) {
+	  kfree(msg);
+	  return -ENAMETOOLONG;
+	}
+	if (strlcpy(msg->contents, symname, sizeof(msg->contents)) >= NNPFS_MAX_SYMLINK_CONTENT) {
+	  kfree(msg);
+	  return -ENAMETOOLONG;
+	}
+	XA_CLEAR(&msg->attr);
+	XA_SET_MODE(&msg->attr, 0777);
+	XA_SET_TYPE(&msg->attr, NNPFS_FILE_LNK);
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,28)
+	XA_SET_GID(&msg->attr, current->fsgid);
+#else
+        XA_SET_GID(&msg->attr, current_fsgid());
+#endif
+
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,28)
+	msg->cred.uid = current->uid;
+#else
+        msg->cred.uid = current_uid();
+#endif
+	msg->cred.pag = nnpfs_get_pag();
+	error = nnpfs_message_rpc(nnpfsp, &msg->header, sizeof(struct nnpfs_message_symlink));
 	if (error == 0)
-	    error = NNPFS_MSG_WAKEUP_ERROR(&msg);
+	    error = NNPFS_MSG_WAKEUP_ERROR(msg);
 
 	/* XXX should this really be here */
 	if (DENTRY_TO_XDENTRY(dentry)->xd_flags == 0) {
 	    printk(KERN_EMERG "NNPFS Panic: nnpfs_symlink: dentry not valid\n");
 	}
+	kfree(msg);
     }
 
     return error;
@@ -1398,7 +1491,11 @@ nnpfs_setattr (struct dentry *dentry, st
         struct nnpfs_message_putattr msg;
 
         msg.header.opcode = NNPFS_MSG_PUTATTR;
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,28)
 	msg.cred.uid = current->uid;
+#else
+        msg.cred.uid = current_uid();
+#endif
 	msg.cred.pag = nnpfs_get_pag();
         msg.handle = xn->handle;
         nnpfs_iattr2attr(xn, attr, &msg.attr);
@@ -1545,6 +1642,8 @@ nnpfs_d_delete(struct dentry *dentry)
     return 0;
 }
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 23)
+
 static ssize_t
 nnpfs_sendfile(struct file *file, loff_t *ppos, size_t count,
 	       read_actor_t actor, void *target)
@@ -1568,6 +1667,33 @@ nnpfs_sendfile(struct file *file, loff_t
     return error;
 }
 
+#else
+
+static ssize_t
+nnpfs_splice_read(struct file *file, loff_t *ppos,
+		  struct pipe_inode_info *pipe, size_t count,
+		  unsigned int flags)
+{
+    int error = 0;
+    struct inode *inode = file->f_dentry->d_inode;
+    struct nnpfs_node *xn = VNODE_TO_XNODE(inode);
+    
+    if (xn != NULL)
+	NNPFSDEB(XDEBVNOPS, ("nnpfs_sendfile: tokens: 0x%x\n", xn->tokens));
+
+    error = nnpfs_data_valid(inode, NNPFS_DATA_R, *ppos, *ppos + count);
+    if (error) {
+	NNPFSDEB(XDEBVNOPS, ("nnpfs_sendfile: data not valid %d\n", error));
+	return error;
+    }
+    error = file->f_op->splice_read(file, ppos, pipe, count, flags);
+
+    NNPFSDEB(XDEBVNOPS, ("nnpfs_sendfile: error = %d\n", error));
+    return error;
+}
+
+#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 23) */
+
 /*
  *
  *
@@ -1639,11 +1765,15 @@ nnpfs_write_backpage(struct page *page, 
 	struct address_space *mapping = backfile->f_mapping;
 	unsigned len = PAGE_CACHE_SIZE;
 	struct page *backpage;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)
+	void *fsdata;
+#endif
 	unsigned long offset;
 
 	int error;
 	
 	do {
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
 		backpage = grab_cache_page(mapping, nnpfs_get_backindex(page));
 		if (!backpage) {
 			printk("nnpfs_write_backpage: no page\n");
@@ -1652,21 +1782,36 @@ nnpfs_write_backpage(struct page *page, 
 
 		error = mapping->a_ops->prepare_write(backfile, backpage,
 						      0, len);
+#else
+		error = pagecache_write_begin(backfile, mapping, 0, len,
+				AOP_FLAG_UNINTERRUPTIBLE, &backpage, &fsdata);
+#endif
 		if (!error) {
 			copy_highpage(backpage, page);
 			flush_dcache_page(backpage);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
 			error = mapping->a_ops->commit_write(backfile, backpage,
 							     0, len);
+#else
+			error = pagecache_write_end(backfile, mapping, 0, len,
+					len, backpage, fsdata);
+			if (error > 0)
+				error = 0;
+#endif
 		}
 		if (error == AOP_TRUNCATED_PAGE) {
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
 			page_cache_release(backpage);
+#endif
 			continue;
 		}
 	} while (0);
 
 	offset = page_offset(backpage);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
 	unlock_page(backpage);
 	page_cache_release(backpage);
+#endif
 
 	if (error)
 		printk("nnpfs_write_backpage: EIO\n");
@@ -1872,6 +2017,34 @@ nnpfs_prepare_write(struct file *file, s
 	return ret;
 }
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28)
+
+static int
+nnpfs_write_begin(struct file *file, struct address_space *mapping, loff_t pos,
+unsigned len, unsigned flags, struct page **pagep, void **fsdata)
+{
+	struct page *page;
+	pgoff_t index;
+	unsigned from;
+
+	index = pos >> PAGE_CACHE_SHIFT;
+	from = pos & (PAGE_CACHE_SIZE - 1);
+
+#ifndef AOP_FLAG_NOFS
+	page = __grab_cache_page(mapping, index);
+#else
+	page = grab_cache_page_write_begin(mapping, index, flags);
+#endif
+	if (!page)
+		return -ENOMEM;
+
+	*pagep = page;
+
+	return nnpfs_prepare_write(file, page, from, from+len);
+}
+
+#endif
+
 static int
 nnpfs_commit_write(struct file *file, struct page *page, unsigned from, unsigned to)
 {
@@ -1902,14 +2075,45 @@ nnpfs_commit_write(struct file *file, st
     return 0;
 }
 
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28)
+
+static int
+nnpfs_write_end(struct file *file, struct address_space *mapping, loff_t pos,
+unsigned len, unsigned copied, struct page *page, void *fsdata)
+{
+	unsigned from = pos & (PAGE_CACHE_SIZE - 1);
+
+	/* zero the stale part of the page if we did a short copy */
+	if (copied < len) {
+		void *kaddr = kmap_atomic(page, KM_USER0);
+		memset(kaddr + from + copied, 0, len - copied);
+		flush_dcache_page(page);
+		kunmap_atomic(kaddr, KM_USER0);
+	}
+
+	nnpfs_commit_write(file, page, from, from+copied);
+
+	unlock_page(page);
+	page_cache_release(page);
+
+	return copied;
+}
+
+#endif
+
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
 const
 #endif
 struct address_space_operations nnpfs_aops = {
 	.readpage = nnpfs_readpage,
 	.writepage = nnpfs_writepage,
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
 	.prepare_write = nnpfs_prepare_write,
 	.commit_write = nnpfs_commit_write,
+#else
+	.write_begin = nnpfs_write_begin,
+	.write_end = nnpfs_write_end,
+#endif
 };
 
 /*
@@ -1924,7 +2128,11 @@ struct file_operations nnpfs_file_operat
     .flush	= nnpfs_flush,
     .release	= nnpfs_release_file,
     .fsync	= nnpfs_fsync,
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 23)
     .sendfile	= nnpfs_sendfile,
+#else
+    .splice_read = nnpfs_splice_read,
+#endif
 };
 
 struct file_operations nnpfs_dead_operations = {
diff -uprN arla-0.90/nnpfs/linux/nnpfs_message.c arla-0.90-new/nnpfs/linux/nnpfs_message.c
--- arla-0.90/nnpfs/linux/nnpfs_message.c	2007-01-09 17:33:31.000000000 +0100
+++ arla-0.90-new/nnpfs/linux/nnpfs_message.c	2010-07-11 17:18:26.572458961 +0200
@@ -45,7 +45,7 @@
 #include <linux/mount.h>
 
 #ifdef RCSID
-RCSID("$Id: nnpfs_message.c,v 1.143.2.1 2007/01/09 16:33:31 tol Exp $");
+RCSID("$Id: nnpfs_message.c,v 1.143 2006/12/11 16:40:24 tol Exp $");
 #endif
 
 static void
@@ -605,12 +605,10 @@ gc_block(struct nnpfs *nnpfsp,
     }
 
     if (!nnpfs_block_have_p(xn, offset)) {
-#if 0   /* happens when daemon sends several messages for same block */
 	printk(KERN_EMERG "NNPFS/gc_block: "
 	       "ENOENT (%d,%d,%d,%d) 0x%llx\n", 
 	       xn->handle.a, xn->handle.b, xn->handle.c, xn->handle.d, 
 	       (unsigned long long)offset);
-#endif
 	return -ENOENT;
     }
 
@@ -737,12 +735,23 @@ nnpfs_message_version(struct nnpfs *nnpf
 		   "nnpfs_message_version failed path_lookup, "
 		   "errno: %d\n", error);
 	} else {
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)
 	    nnpfsp->cacheroot = mntget(nd.mnt);
 	    nnpfsp->cachedir = dget(nd.dentry);
 	    path_release(&nd);
+#else
+	    nnpfsp->cacheroot = mntget(nd.path.mnt);
+	    nnpfsp->cachedir = dget(nd.path.dentry);
+	    path_put(&nd.path);
+#endif
 	    
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,28)
 	    nnpfsp->uid = current->fsuid;
 	    nnpfsp->gid = current->fsgid;
+#else
+            nnpfsp->uid = current_fsuid();
+            nnpfsp->gid = current_fsgid();
+#endif
 
 	    /* XXX we should validate these values */
 	    nnpfs_blocksize = blocksize;
diff -uprN arla-0.90/nnpfs/linux/nnpfs_syscalls.c arla-0.90-new/nnpfs/linux/nnpfs_syscalls.c
--- arla-0.90/nnpfs/linux/nnpfs_syscalls.c	2007-01-03 15:26:27.000000000 +0100
+++ arla-0.90-new/nnpfs/linux/nnpfs_syscalls.c	2010-07-11 18:49:01.229639299 +0200
@@ -147,10 +147,16 @@ static int nnpfs_sec_registered = 0;
 #define SEC2PAG(s) (nnpfs_pag_t)(unsigned long)(s)
 #define PAG2SEC(p) (void *)(unsigned long)(p)
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
+
 static int
 nnpfs_sec_task_alloc(struct task_struct *p)
 {
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,28)
     nnpfs_pag_t pag = SEC2PAG(current->security);
+#else
+    nnpfs_pag_t pag = SEC2PAG(current_security());
+#endif
     if (pag)
 	p->security = PAG2SEC(pag);
     return 0;
@@ -164,35 +170,55 @@ nnpfs_sec_task_free(struct task_struct *
 	p->security = NULL;
 }
 
+#endif
+
 static nnpfs_pag_t
 nnpfs_get_pag_sec(void)
 {
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,28)
     nnpfs_pag_t pag = SEC2PAG(current->security);
+#else
+    nnpfs_pag_t pag = SEC2PAG(current_security());
+#endif
     if (pag)
 	return pag;
 
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,28)
     return current->uid;
+#else
+    return current_uid();
+#endif
 }
 
 static int
 nnpfs_set_pag_sec(void)
 {
     static nnpfs_pag_t pagnum = NNPFS_PAG_LLIM;
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29)
+    struct cred *cred;
+#endif
 
     if (pagnum == NNPFS_PAG_ULIM)
 	return -ENOMEM;
     /* pagnum = NNPFS_PAG_LLIM; */
     
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,28)
     current->security = PAG2SEC(pagnum);
+#else
+    cred = (struct cred *) current->cred;
+    cred->security = PAG2SEC(pagnum);
+#endif
     pagnum++;
     return 0;
 }
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
 static struct security_operations nnpfs_sec_ops = {
     .task_alloc_security = nnpfs_sec_task_alloc,
     .task_free_security = nnpfs_sec_task_free,
 //    .task_reparent_to_init = nnpfs_sec_reparent_to_init,
 };
+#endif
 
 #endif /* CONFIG_SECURITY */
 
@@ -222,11 +248,18 @@ find_pag(struct group_info *gi)
 static nnpfs_pag_t
 nnpfs_get_pag_group(void)
 {
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,28)
     struct group_info *gi = current->group_info;
     nnpfs_pag_t ret = current->uid;
+#else
+    struct group_info *gi = get_current_groups();
+    nnpfs_pag_t ret = current_uid();
+#endif
     int i;
 
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,28)
     get_group_info(gi);
+#endif
 
     i = find_pag(gi);
     if (i != NNPFS_PAG_NOTFOUND)
@@ -242,13 +275,23 @@ nnpfs_get_pag_group(void)
 static int
 store_pag(nnpfs_pag_t pagnum)
 {
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,28)
     struct group_info *old_gi = current->group_info;
+#else
+   struct group_info *old_gi = get_current_groups();
+#endif
     struct group_info *new_gi;
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)
     int nblocks, count;
+#else
+    unsigned int nblocks, count;
+#endif
     int found = 0;
     int i, k;
     
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,28)    
     get_group_info(old_gi);
+#endif
 
     i = find_pag(old_gi);
     if (i != NNPFS_PAG_NOTFOUND)
@@ -317,7 +360,11 @@ nnpfs_get_pag()
     return nnpfs_get_pag_group();
 #endif /* GROUPPAGS */
 
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,28)
     return current->uid;
+#else
+    return current_uid();
+#endif
 }
 
 static inline int
@@ -528,7 +575,11 @@ user_path2dentry (struct nameidata *nd, 
     putname(kname);
     if (error)
 	return ERR_PTR(error);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)
     return nd->dentry;
+#else
+    return nd->path.dentry;
+#endif
 }
 
 asmlinkage long
@@ -540,11 +591,16 @@ sys_afs_int (int operation,
 {
     long error = 0;
     struct arlaViceIoctl vice_ioctl; 
-    struct nnpfs_message_pioctl msg;
+    struct nnpfs_message_pioctl *msg = NULL;
     struct nnpfs_message_wakeup *msg2;
     struct dentry *dentry = NULL;
     struct nameidata nd;
-    
+
+    msg = kmalloc(sizeof(struct nnpfs_message_pioctl), GFP_KERNEL);
+
+    if (!msg)
+      return -ENOMEM;
+
     lock_kernel();
 
     NNPFSDEB(XDEBSYS, ("sys_afs kernel locked\n"));
@@ -575,7 +631,7 @@ sys_afs_int (int operation,
 	    goto unlock;
 	}
 	if (vice_ioctl.in_size != 0) {
-	    if(copy_from_user(&msg.msg,
+	    if(copy_from_user(&msg->msg,
 			      vice_ioctl.in,
 			      vice_ioctl.in_size) != 0) {
 		error = -EFAULT;
@@ -628,19 +684,23 @@ sys_afs_int (int operation,
 		error = -EINVAL;
 		goto unlock;
 	    }
-	    msg.handle = xn->handle;
+	    msg->handle = xn->handle;
 	}
 
-	msg.header.opcode = NNPFS_MSG_PIOCTL;
-	msg.opcode = a_opcode;
+	msg->header.opcode = NNPFS_MSG_PIOCTL;
+	msg->opcode = a_opcode;
 	
-	msg.insize   = vice_ioctl.in_size;
-	msg.outsize  = vice_ioctl.out_size;
-	msg.cred.uid = current->uid;
-	msg.cred.pag = nnpfs_get_pag();
+	msg->insize   = vice_ioctl.in_size;
+	msg->outsize  = vice_ioctl.out_size;
+#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,28)
+	msg->cred.uid = current->uid;
+#else
+        msg->cred.uid = current_uid();
+#endif
+	msg->cred.pag = nnpfs_get_pag();
 	
-	error = nnpfs_message_rpc(&nnpfs[0], &msg.header, sizeof(msg)); /* XXX */
-	msg2 = (struct nnpfs_message_wakeup *) &msg;
+	error = nnpfs_message_rpc(&nnpfs[0], &msg->header, sizeof(struct nnpfs_message_pioctl)); /* XXX */
+	msg2 = (struct nnpfs_message_wakeup *) msg;
 	if (error == 0)
 	    error = msg2->error;
 
@@ -675,11 +735,16 @@ sys_afs_int (int operation,
     
  unlock:
     if (dentry)
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)
 	path_release(&nd);
+#else
+	path_put(&nd.path);
+#endif
 
     NNPFSDEB(XDEBSYS, ("nnpfs_syscall returns error: %ld\n", error));
 
     NNPFSDEB(XDEBSYS, ("sys_afs kernel unlock\n"));
+    kfree(msg);
     unlock_kernel();
 
     return error;
@@ -780,20 +845,32 @@ static int nnpfs_init_procfs(void)
 {
     struct proc_dir_entry *entry;
     
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)
     nnpfs_procfs_dir = proc_mkdir(NNPFS_PROC_DIR, proc_root_fs);
+#else
+    nnpfs_procfs_dir = proc_mkdir("fs/" NNPFS_PROC_DIR, NULL);
+#endif
     if (nnpfs_procfs_dir == NULL)
 	return -ENOMEM;
     
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
     nnpfs_procfs_dir->owner = THIS_MODULE;
+#endif
     
     entry = create_proc_entry(NNPFS_PROC_NODE, 0666, nnpfs_procfs_dir);
     if (entry == NULL) {
 	NNPFSDEB(XDEBSYS, ("nnpfs_init_procfs: no node\n"));
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)
 	remove_proc_entry(NNPFS_PROC_DIR, proc_root_fs);
+#else
+	remove_proc_entry("fs/" NNPFS_PROC_DIR, NULL);
+#endif
 	return -ENOMEM;
     }
     
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30)
     entry->owner = THIS_MODULE;
+#endif
     entry->proc_fops = &nnpfs_procfs_fops;
 
 #ifdef SYSCALLCOMPAT
@@ -815,7 +892,11 @@ static void nnpfs_exit_procfs(void)
     }
 #endif /* SYSCALLCOMPAT */
     remove_proc_entry(NNPFS_PROC_NODE, nnpfs_procfs_dir);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)
     remove_proc_entry(NNPFS_PROC_DIR, proc_root_fs);
+#else
+    remove_proc_entry("fs/" NNPFS_PROC_DIR, NULL);
+#endif
 }
 
 #ifdef GROUPPAGS
@@ -840,12 +921,14 @@ void
 install_afs_syscall(void)
 {
 #ifdef CONFIG_SECURITY
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
     if (register_security(&nnpfs_sec_ops))
 	NNPFSDEB(XDEBSYS,
 		 ("install_afs_syscall: nnpfs_init_sec failed\n"));
     else
 	nnpfs_sec_registered = 1;
 #endif
+#endif
 
     nnpfs_init_procfs();
 
@@ -888,9 +971,11 @@ restore_afs_syscall (void)
 #endif /* SYSCALLHACK */
 
 #ifdef CONFIG_SECURITY
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
     if (nnpfs_sec_registered)
 	if (unregister_security(&nnpfs_sec_ops))
 	    printk(KERN_EMERG "nnpfs_exit_sec: couldn't unregister\n");
+#endif
 #endif /* !CONFIG_SECURITY */
 
 #ifdef GROUPPAGS
diff -uprN arla-0.90/nnpfs/linux/nnpfs_syscalls-lossage.c arla-0.90-new/nnpfs/linux/nnpfs_syscalls-lossage.c
--- arla-0.90/nnpfs/linux/nnpfs_syscalls-lossage.c	2006-12-11 17:31:45.000000000 +0100
+++ arla-0.90-new/nnpfs/linux/nnpfs_syscalls-lossage.c	2010-07-11 17:18:26.572458961 +0200
@@ -63,6 +63,11 @@ const char * __attribute__((weak))
 		    unsigned long *offset,
 		    char **modname, char *namebuf);
 
+#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,18)
+#ifdef __x86_64__
+extern rwlock_t tasklist_lock __attribute__((weak));
+#endif
+#endif
 static void **
 get_start_addr(void) {
 #ifdef __x86_64__
diff -uprN arla-0.90/nnpfs/linux/nnpfs_vfsops.c arla-0.90-new/nnpfs/linux/nnpfs_vfsops.c
--- arla-0.90/nnpfs/linux/nnpfs_vfsops.c	2006-12-11 17:43:35.000000000 +0100
+++ arla-0.90-new/nnpfs/linux/nnpfs_vfsops.c	2010-07-11 17:18:26.577958688 +0200
@@ -49,9 +49,13 @@ RCSID("$Id: nnpfs_vfsops.c,v 1.109 2006/
 
 struct nnpfs nnpfs[NNNPFS];
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)
 static void nnpfs_read_inode(struct inode *inode);
+#endif
 static void nnpfs_put_super(struct super_block *sb);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)
 static void nnpfs_put_inode(struct inode *inode);
+#endif
 static void nnpfs_write_super(struct super_block * sb);
 
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,18)
@@ -61,8 +65,10 @@ static int nnpfs_statfs(struct super_blo
 #endif
 
 static struct super_operations nnpfs_sops = { 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)
     read_inode		: nnpfs_read_inode,
     put_inode		: nnpfs_put_inode,
+#endif
     alloc_inode		: nnpfs_node_alloc,
     destroy_inode	: nnpfs_node_free,
     drop_inode		: generic_delete_inode,
@@ -189,7 +195,11 @@ nnpfs_read_super (struct super_block * s
 	if (error)
 	    ddev = ERR_PTR(error);
 	else
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)
 	    ddev = nd.dentry;
+#else
+	    ddev = nd.path.dentry;
+#endif
 
 	if (!IS_ERR(ddev)) {
 	    minordevice = MINOR(ddev->d_inode->i_rdev);
@@ -273,6 +283,7 @@ nnpfs_put_super(struct super_block *sb)
     NNPFSDEB(XDEBVFOPS, ("nnpfs_put_super exiting\n"));
 }
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)
 static void
 nnpfs_read_inode(struct inode *inode)
 {
@@ -339,6 +350,7 @@ nnpfs_put_inode(struct inode *inode)
 
     up(&nnpfsp->inactive_sem);
 }
+#endif // LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)
 
 static int
 nnpfs_statfs_int(struct super_block *sb, struct kstatfs *buf)
@@ -352,7 +364,15 @@ nnpfs_statfs_int(struct super_block *sb,
     tmp.f_bavail  = 1024*1024*2-50;
     tmp.f_files   = 1024*1024;
     tmp.f_ffree   = 1024*1024-100;
+    tmp.f_fsid.val[0] = 0;
+    tmp.f_fsid.val[1] = 0;
     tmp.f_namelen = NAME_MAX;
+    tmp.f_frsize  = 0;
+    tmp.f_spare[0] = 0;
+    tmp.f_spare[1] = 0;
+    tmp.f_spare[2] = 0;
+    tmp.f_spare[3] = 0;
+    tmp.f_spare[4] = 0;
     *buf = tmp;
     return 0;
 }


More information about the Arla-drinkers mailing list