Re: PATCH: Arla CVS Current on Linux 2.6.24 to Linux 2.6.28

Bo Brantén <[email protected]>
Newsgroups gmane.comp.file-systems.arla.general
Message-ID <[email protected]>
Small change in write handling.

>
> And another small bug fix.
>
>> 
>> Hello,
>> 
>> new patch again, this fixes a write bug in kernel 2.6.24 and later.
>> 
>> Bo Branten
>

_______________________________________________
Arla-drinkers mailing list
[email protected]
https://lists.stacken.kth.se/mailman/listinfo/arla-drinkers
nypatch-cvs (text/plain, 13.2 KB)
diff -uprN arla-cvs/nnpfs/linux/nnpfs_blocks.c arla-cvs-new/nnpfs/linux/nnpfs_blocks.c
--- arla-cvs/nnpfs/linux/nnpfs_blocks.c	2008-03-08 22:38:16.000000000 +0100
+++ arla-cvs-new/nnpfs/linux/nnpfs_blocks.c	2008-12-15 17:58:11.000000000 +0100
@@ -403,12 +403,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);
@@ -422,12 +431,20 @@ 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);
+#else
+	struct file *f = dentry_open(nd.path.dentry, nd.path.mnt, flags);
+#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;
 	}
diff -uprN arla-cvs/nnpfs/linux/nnpfs_inodeops.c arla-cvs-new/nnpfs/linux/nnpfs_inodeops.c
--- arla-cvs/nnpfs/linux/nnpfs_inodeops.c	2008-03-08 22:40:10.000000000 +0100
+++ arla-cvs-new/nnpfs/linux/nnpfs_inodeops.c	2008-12-17 15:47:39.000000000 +0100
@@ -138,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
 
 /*
  *
@@ -596,8 +598,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();
@@ -1672,11 +1679,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");
@@ -1685,21 +1696,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");
@@ -1905,6 +1931,30 @@ 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);
+
+	page = __grab_cache_page(mapping, index);
+	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)
 {
@@ -1935,14 +1985,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
 };
 
 /*
diff -uprN arla-cvs/nnpfs/linux/nnpfs_message.c arla-cvs-new/nnpfs/linux/nnpfs_message.c
--- arla-cvs/nnpfs/linux/nnpfs_message.c	2006-12-11 17:40:24.000000000 +0100
+++ arla-cvs-new/nnpfs/linux/nnpfs_message.c	2008-12-15 17:58:11.000000000 +0100
@@ -735,9 +735,15 @@ 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
 	    
 	    nnpfsp->uid = current->fsuid;
 	    nnpfsp->gid = current->fsgid;
diff -uprN arla-cvs/nnpfs/linux/nnpfs_syscalls.c arla-cvs-new/nnpfs/linux/nnpfs_syscalls.c
--- arla-cvs/nnpfs/linux/nnpfs_syscalls.c	2007-01-03 15:26:27.000000000 +0100
+++ arla-cvs-new/nnpfs/linux/nnpfs_syscalls.c	2008-12-15 17:58:11.000000000 +0100
@@ -147,6 +147,8 @@ 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)
 {
@@ -164,6 +166,8 @@ nnpfs_sec_task_free(struct task_struct *
 	p->security = NULL;
 }
 
+#endif
+
 static nnpfs_pag_t
 nnpfs_get_pag_sec(void)
 {
@@ -188,11 +192,13 @@ nnpfs_set_pag_sec(void)
     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 */
 
@@ -244,7 +250,11 @@ store_pag(nnpfs_pag_t pagnum)
 {
     struct group_info *old_gi = current->group_info;
     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;
     
@@ -528,7 +538,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
@@ -675,7 +689,11 @@ 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));
 
@@ -780,7 +798,11 @@ 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;
     
@@ -789,7 +811,11 @@ static int nnpfs_init_procfs(void)
     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;
     }
     
@@ -815,7 +841,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 +870,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 +920,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-cvs/nnpfs/linux/nnpfs_syscalls-lossage.c arla-cvs-new/nnpfs/linux/nnpfs_syscalls-lossage.c
--- arla-cvs/nnpfs/linux/nnpfs_syscalls-lossage.c	2006-12-11 17:31:45.000000000 +0100
+++ arla-cvs-new/nnpfs/linux/nnpfs_syscalls-lossage.c	2008-12-15 17:58:11.000000000 +0100
@@ -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-cvs/nnpfs/linux/nnpfs_vfsops.c arla-cvs-new/nnpfs/linux/nnpfs_vfsops.c
--- arla-cvs/nnpfs/linux/nnpfs_vfsops.c	2006-12-11 17:43:35.000000000 +0100
+++ arla-cvs-new/nnpfs/linux/nnpfs_vfsops.c	2008-12-15 17:58:11.000000000 +0100
@@ -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;
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.