No subject

Bo Brantén bosse at acc.umu.se
Thu Nov 6 20:57:11 CET 2008


Hello,

A while ago they added write_begin/write_end to struct
address_space_operations that is intended to replace
prepare_write/commit_write who is removed in kernel
version 2.6.28, here is a patch for nnpfs to take care
of that, it is not tested yet but I post it for review
and comments.

Bo Branten
-------------- next part --------------
--- nnpfs/linux/nnpfs_inodeops.bak	2008-03-08 22:40:10.000000000 +0100
+++ nnpfs/linux/nnpfs_inodeops.c	2008-11-06 20:44:50.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,28)
+	void *fsdata;
+#endif
 	unsigned long offset;
 
 	int error;
 	
 	do {
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
 		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 = mapping->a_ops->write_begin(backfile, mapping,
+						     0, len, 0, &backpage,
+						     &fsdata);
+#endif
 		if (!error) {
 			copy_highpage(backpage, page);
 			flush_dcache_page(backpage);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
 			error = mapping->a_ops->commit_write(backfile, backpage,
 							     0, len);
+#else
+			error = mapping->a_ops->write_end(backfile, mapping,
+							  0, len, len,
+							  backpage, fsdata);
+#endif
 		}
 		if (error == AOP_TRUNCATED_PAGE) {
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
 			page_cache_release(backpage);
+#endif
 			continue;
 		}
 	} while (0);
 
 	offset = page_offset(backpage);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)
 	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
 };
 
 /*


More information about the Arla-drinkers mailing list