dazuko-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dazuko-devel] Patch 7/7


From: Lino Sanfilippo
Subject: [Dazuko-devel] Patch 7/7
Date: Fri, 06 Aug 2010 10:23:32 +0200
User-agent: Mozilla-Thunderbird 2.0.0.24 (X11/20100329)

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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]