~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to fs/ecryptfs/mmap.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
{
63
63
        int rc;
64
64
 
 
65
        /*
 
66
         * Refuse to write the page out if we are called from reclaim context
 
67
         * since our writepage() path may potentially allocate memory when
 
68
         * calling into the lower fs vfs_write() which may in turn invoke
 
69
         * us again.
 
70
         */
 
71
        if (current->flags & PF_MEMALLOC) {
 
72
                redirty_page_for_writepage(wbc, page);
 
73
                rc = 0;
 
74
                goto out;
 
75
        }
 
76
 
65
77
        rc = ecryptfs_encrypt_page(page);
66
78
        if (rc) {
67
79
                ecryptfs_printk(KERN_WARNING, "Error encrypting "
70
82
                goto out;
71
83
        }
72
84
        SetPageUptodate(page);
 
85
out:
73
86
        unlock_page(page);
74
 
out:
75
87
        return rc;
76
88
}
77
89
 
193
205
                &ecryptfs_inode_to_private(page->mapping->host)->crypt_stat;
194
206
        int rc = 0;
195
207
 
196
 
        if (!crypt_stat
197
 
            || !(crypt_stat->flags & ECRYPTFS_ENCRYPTED)
198
 
            || (crypt_stat->flags & ECRYPTFS_NEW_FILE)) {
199
 
                ecryptfs_printk(KERN_DEBUG,
200
 
                                "Passing through unencrypted page\n");
 
208
        if (!crypt_stat || !(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) {
201
209
                rc = ecryptfs_read_lower_page_segment(page, page->index, 0,
202
210
                                                      PAGE_CACHE_SIZE,
203
211
                                                      page->mapping->host);
295
303
                struct ecryptfs_crypt_stat *crypt_stat =
296
304
                        &ecryptfs_inode_to_private(mapping->host)->crypt_stat;
297
305
 
298
 
                if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)
299
 
                    || (crypt_stat->flags & ECRYPTFS_NEW_FILE)) {
 
306
                if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) {
300
307
                        rc = ecryptfs_read_lower_page_segment(
301
308
                                page, index, 0, PAGE_CACHE_SIZE, mapping->host);
302
309
                        if (rc) {
491
498
        struct ecryptfs_crypt_stat *crypt_stat =
492
499
                &ecryptfs_inode_to_private(ecryptfs_inode)->crypt_stat;
493
500
        int rc;
 
501
        int need_unlock_page = 1;
494
502
 
495
 
        if (crypt_stat->flags & ECRYPTFS_NEW_FILE) {
496
 
                ecryptfs_printk(KERN_DEBUG, "ECRYPTFS_NEW_FILE flag set in "
497
 
                        "crypt_stat at memory location [%p]\n", crypt_stat);
498
 
                crypt_stat->flags &= ~(ECRYPTFS_NEW_FILE);
499
 
        } else
500
 
                ecryptfs_printk(KERN_DEBUG, "Not a new file\n");
501
503
        ecryptfs_printk(KERN_DEBUG, "Calling fill_zeros_to_end_of_page"
502
504
                        "(page w/ index = [0x%.16lx], to = [%d])\n", index, to);
503
505
        if (!(crypt_stat->flags & ECRYPTFS_ENCRYPTED)) {
517
519
                        "zeros in page with index = [0x%.16lx]\n", index);
518
520
                goto out;
519
521
        }
520
 
        rc = ecryptfs_encrypt_page(page);
521
 
        if (rc) {
522
 
                ecryptfs_printk(KERN_WARNING, "Error encrypting page (upper "
523
 
                                "index [0x%.16lx])\n", index);
524
 
                goto out;
525
 
        }
 
522
        set_page_dirty(page);
 
523
        unlock_page(page);
 
524
        need_unlock_page = 0;
526
525
        if (pos + copied > i_size_read(ecryptfs_inode)) {
527
526
                i_size_write(ecryptfs_inode, pos + copied);
528
527
                ecryptfs_printk(KERN_DEBUG, "Expanded file size to "
529
528
                        "[0x%.16llx]\n",
530
529
                        (unsigned long long)i_size_read(ecryptfs_inode));
 
530
                balance_dirty_pages_ratelimited(mapping);
 
531
                rc = ecryptfs_write_inode_size_to_metadata(ecryptfs_inode);
 
532
                if (rc) {
 
533
                        printk(KERN_ERR "Error writing inode size to metadata; "
 
534
                               "rc = [%d]\n", rc);
 
535
                        goto out;
 
536
                }
531
537
        }
532
 
        rc = ecryptfs_write_inode_size_to_metadata(ecryptfs_inode);
533
 
        if (rc)
534
 
                printk(KERN_ERR "Error writing inode size to metadata; "
535
 
                       "rc = [%d]\n", rc);
536
 
        else
537
 
                rc = copied;
 
538
        rc = copied;
538
539
out:
539
 
        unlock_page(page);
 
540
        if (need_unlock_page)
 
541
                unlock_page(page);
540
542
        page_cache_release(page);
541
543
        return rc;
542
544
}