Patch 7/7

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Patch 7/7

Lino Sanfilippo
This patch implements writing via memory mapping for dazukofs:

In writepage() we look for the corresponding lower page and create it if it
does not exist.
Then we copy the content of the upper page to the lower page and mark it
dirty.
This causes marked pages to be written to disk as soon as the pages are
synced (i.e
due to an msync() or sync()).

Note that this patch also removes some of the functions that do also cause
writepage() to be called, like generic_file_aio_[read|write] and
splice_read() since
mmap has not been tested in conjunction with these functions - also
writebegin()
should not be called any more now.

With this the only address space operations that we should need are
readpage()
and writepage() and both are only needed for the memory mapping feature
and nothing else.





Geschäftsführender Gesellschafter: Tjark Auerbach
Sitz der Gesellschaft: Tettnang
Handelsregister: Amtsgericht Ulm, HRB 630992
ALLGEMEINE GESCHÄFTSBEDINGUNGEN
Es gelten unsere Allgemeinen Geschäftsbedingungen
(AGB). Sie finden sie in der jeweils gültigen Fassung
im Internet unter http://www.avira.de/agb
***************************************************

diff -Nurp dazukofs-3.1.3-patch6/file.c dazukofs-3.1.3-patch7/file.c
--- dazukofs-3.1.3-patch6/file.c 2010-08-06 10:04:06.000000000 +0200
+++ dazukofs-3.1.3-patch7/file.c 2010-08-05 19:33:26.000000000 +0200
@@ -138,11 +138,11 @@ static ssize_t dazukofs_write(struct fil
  lower_file->f_pos = pos_copy;
 
  if (rv >= 0) {
-                /* mark all upper pages concerned by the write to lower file as
-                   not Uptodate.
-                   NOTE: we dont use the offset given with ppos, but calculate
-                   it from the _returned_ value, since in some cases (O_APPEND)
-                   the file pointer will have been modified subsequently. */
+ /* mark all upper pages concerned by the write to lower file as
+   not Uptodate.
+   NOTE: we dont use the offset given with ppos, but calculate
+   it from the _returned_ value, since in some cases (O_APPEND)
+   the file pointer will have been modified subsequently. */
  mark_pages_dirty(file, rv, pos_copy - rv);
  fsstack_copy_attr_atime(inode, lower_inode);
  }
@@ -280,7 +280,7 @@ static int dazukofs_fsync(struct file *f
  if (!lower_file->f_op || !lower_file->f_op->fsync)
  return -EINVAL;
 
- return lower_file->f_op->fsync(lower_file, lower_dentry, datasync);
+ return vfs_fsync(lower_file, lower_dentry, datasync);
 }
 
 /**
@@ -307,7 +307,7 @@ static int dazukofs_mmap(struct file *fi
  if (!lower_file->f_op || !lower_file->f_op->mmap)
  return -ENODEV;
 
- return generic_file_readonly_mmap(file, vm);
+ return generic_file_mmap(file, vm);
 }
 
 /**
@@ -332,9 +332,13 @@ static int dazukofs_mmap(struct file *fi
 const struct file_operations dazukofs_main_fops = {
  .llseek = dazukofs_llseek,
  .read = dazukofs_read,
+#if 0
  .aio_read = generic_file_aio_read,
+#endif
  .write = dazukofs_write,
+#if 0
  .aio_write = generic_file_aio_write,
+#endif
  .readdir = dazukofs_readdir,
  .ioctl = dazukofs_ioctl,
  .mmap = dazukofs_mmap,
@@ -343,7 +347,9 @@ const struct file_operations dazukofs_ma
  .release = dazukofs_release,
  .fsync = dazukofs_fsync,
  .fasync = dazukofs_fasync,
+#if 0
  .splice_read = generic_file_splice_read,
+#endif
 };
 
 /**
@@ -378,5 +384,7 @@ const struct file_operations dazukofs_di
  .release = dazukofs_release,
  .fsync = dazukofs_fsync,
  .fasync = dazukofs_fasync,
+#if 0
  .splice_read = generic_file_splice_read,
+#endif
 };
diff -Nurp dazukofs-3.1.3-patch6/mmap.c dazukofs-3.1.3-patch7/mmap.c
--- dazukofs-3.1.3-patch6/mmap.c 2010-08-05 15:54:31.000000000 +0200
+++ dazukofs-3.1.3-patch7/mmap.c 2010-08-05 17:50:29.000000000 +0200
@@ -27,11 +27,6 @@
 
 #include "dazukofs_fs.h"
 
-static int dazukofs_writepage(struct page *page, struct writeback_control *wbc)
-{
- /* mmap read-only */
- return -EINVAL;
-}
 
 /**
  * Description: Called by the VM to read a page from backing store. The page
@@ -103,10 +98,71 @@ int dazukofs_write_begin(struct file *f,
  struct page **pagep, void **fsdata)
 {
  /* mmap read-only */
+ BUG();
  return -EINVAL;
 }
 
 /**
+ * Called if a page fault occured due to reading or writing to upper  mmaped
+ * file. We get the lower page and mark it dirty, we DONT call lower
+ * writepage() yet. Instead we let this be done by msync() or other kernel
+ * facilities (pdflush) that try to write pages to disc.
+ */
+static int dazukofs_writepage(struct page *page, struct writeback_control *wbc)
+{
+ struct inode *inode = page->mapping->host;
+ struct inode *lower_inode = get_lower_inode(inode);
+ struct page *lower_page;
+ char *page_data;
+ char *lower_page_data;
+ int rv = 0;
+
+ /* get lower page or create it if it does not exist */
+ lower_page = grab_cache_page(lower_inode->i_mapping, page->index);
+
+ if (!lower_page) {
+ printk(KERN_ERR "dazukofs: Failed to grab lower page\n");
+ rv = -ENOMEM;
+ goto fail;
+ }
+
+ page_data = (char *) kmap(page);
+ if (!page_data) {
+ rv = -ENOMEM;
+ printk(KERN_ERR "dazukofs: Error mapping page.\n");
+ unlock_page(lower_page);
+ goto fail;
+ }
+
+ lower_page_data = (char *) kmap(lower_page);
+ if (!lower_page_data) {
+ rv = -ENOMEM;
+ printk(KERN_ERR "dazukofs: Error mapping lower page.\n");
+ kunmap(page);
+ unlock_page(lower_page);
+ goto fail;
+ }
+
+ memcpy(lower_page_data, page_data, PAGE_CACHE_SIZE);
+
+ kunmap(page);
+ kunmap(lower_page);
+
+ /* Mark lower page dirty, also update dirty tags in radix tree.
+           Dont call lower writepage() yet. */
+ set_page_dirty(lower_page);
+ unlock_page(lower_page);
+
+ SetPageUptodate(page);
+
+fail:
+ unlock_page(page);
+
+ return rv;
+}
+
+
+/**
  * Unused operations:
  *   - sync_page
  *   - writepages

_______________________________________________
Dazuko-devel mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/dazuko-devel
Reply | Threaded
Open this post in threaded view
|

Re: Patch 7/7

John Ogness-10
On 2010-08-06, Lino Sanfilippo <[hidden email]> wrote:

> This patch implements writing via memory mapping for dazukofs:
>
> In writepage() we look for the corresponding lower page and create
> it if it does not exist.  Then we copy the content of the upper page
> to the lower page and mark it dirty.  This causes marked pages to be
> written to disk as soon as the pages are synced (i.e due to an
> msync() or sync()).
>
> Note that this patch also removes some of the functions that do also
> cause writepage() to be called, like generic_file_aio_[read|write]
> and splice_read() since mmap has not been tested in conjunction with
> these functions - also writebegin() should not be called any more
> now.
>
> With this the only address space operations that we should need are
> readpage() and writepage() and both are only needed for the memory
> mapping feature and nothing else.

I am not comfortable accepting a patch full of "#if 0" and "BUG()"
lines. I have the feeling you aren't confident that these major
changes are safe.

If you are certain that supporting mmap-write is safe, please send a
new patch against 3.1.4-rc1 that is not full of debug stuff.

John Ogness

--
Dazuko Maintainer

_______________________________________________
Dazuko-devel mailing list
[hidden email]
http://lists.nongnu.org/mailman/listinfo/dazuko-devel