diff options
author | Michael Halcrow <mhalcrow@us.ibm.com> | 2007-10-16 04:28:14 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-10-16 12:43:12 -0400 |
commit | 16a72c455a67bb23eed7292a31c6ba17729e78e6 (patch) | |
tree | d2cc7d116730348375ce0d06ad45e24744cd0b5f /fs/ecryptfs/read_write.c | |
parent | ecbdc93639f69c1f237ccce6a9aaff1e83f1182f (diff) |
ecryptfs: clean up page flag handling
The functions that eventually call down to ecryptfs_read_lower(),
ecryptfs_decrypt_page(), and ecryptfs_copy_up_encrypted_with_header()
should have the responsibility of managing the page Uptodate
status. This patch gets rid of some of the ugliness that resulted from
trying to push some of the page flag setting too far down the stack.
Signed-off-by: Michael Halcrow <mhalcrow@us.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/ecryptfs/read_write.c')
-rw-r--r-- | fs/ecryptfs/read_write.c | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c index 272eaeb9a738..2150edf9a58e 100644 --- a/fs/ecryptfs/read_write.c +++ b/fs/ecryptfs/read_write.c | |||
@@ -142,8 +142,8 @@ int ecryptfs_write(struct file *ecryptfs_file, char *data, loff_t offset, | |||
142 | if (num_bytes > total_remaining_zeros) | 142 | if (num_bytes > total_remaining_zeros) |
143 | num_bytes = total_remaining_zeros; | 143 | num_bytes = total_remaining_zeros; |
144 | } | 144 | } |
145 | ecryptfs_page = ecryptfs_get1page(ecryptfs_file, | 145 | ecryptfs_page = ecryptfs_get_locked_page(ecryptfs_file, |
146 | ecryptfs_page_idx); | 146 | ecryptfs_page_idx); |
147 | if (IS_ERR(ecryptfs_page)) { | 147 | if (IS_ERR(ecryptfs_page)) { |
148 | rc = PTR_ERR(ecryptfs_page); | 148 | rc = PTR_ERR(ecryptfs_page); |
149 | printk(KERN_ERR "%s: Error getting page at " | 149 | printk(KERN_ERR "%s: Error getting page at " |
@@ -161,6 +161,7 @@ int ecryptfs_write(struct file *ecryptfs_file, char *data, loff_t offset, | |||
161 | printk(KERN_ERR "%s: Error decrypting " | 161 | printk(KERN_ERR "%s: Error decrypting " |
162 | "page; rc = [%d]\n", | 162 | "page; rc = [%d]\n", |
163 | __FUNCTION__, rc); | 163 | __FUNCTION__, rc); |
164 | ClearPageUptodate(ecryptfs_page); | ||
164 | page_cache_release(ecryptfs_page); | 165 | page_cache_release(ecryptfs_page); |
165 | goto out; | 166 | goto out; |
166 | } | 167 | } |
@@ -180,14 +181,15 @@ int ecryptfs_write(struct file *ecryptfs_file, char *data, loff_t offset, | |||
180 | } | 181 | } |
181 | kunmap_atomic(ecryptfs_page_virt, KM_USER0); | 182 | kunmap_atomic(ecryptfs_page_virt, KM_USER0); |
182 | flush_dcache_page(ecryptfs_page); | 183 | flush_dcache_page(ecryptfs_page); |
184 | SetPageUptodate(ecryptfs_page); | ||
185 | unlock_page(ecryptfs_page); | ||
183 | rc = ecryptfs_encrypt_page(ecryptfs_page); | 186 | rc = ecryptfs_encrypt_page(ecryptfs_page); |
187 | page_cache_release(ecryptfs_page); | ||
184 | if (rc) { | 188 | if (rc) { |
185 | printk(KERN_ERR "%s: Error encrypting " | 189 | printk(KERN_ERR "%s: Error encrypting " |
186 | "page; rc = [%d]\n", __FUNCTION__, rc); | 190 | "page; rc = [%d]\n", __FUNCTION__, rc); |
187 | page_cache_release(ecryptfs_page); | ||
188 | goto out; | 191 | goto out; |
189 | } | 192 | } |
190 | page_cache_release(ecryptfs_page); | ||
191 | pos += num_bytes; | 193 | pos += num_bytes; |
192 | } | 194 | } |
193 | if ((offset + size) > ecryptfs_file_size) { | 195 | if ((offset + size) > ecryptfs_file_size) { |
@@ -225,7 +227,6 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size, | |||
225 | ecryptfs_inode_to_private(ecryptfs_inode); | 227 | ecryptfs_inode_to_private(ecryptfs_inode); |
226 | ssize_t octets_read; | 228 | ssize_t octets_read; |
227 | mm_segment_t fs_save; | 229 | mm_segment_t fs_save; |
228 | size_t i; | ||
229 | int rc = 0; | 230 | int rc = 0; |
230 | 231 | ||
231 | mutex_lock(&inode_info->lower_file_mutex); | 232 | mutex_lock(&inode_info->lower_file_mutex); |
@@ -242,16 +243,6 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size, | |||
242 | rc = -EINVAL; | 243 | rc = -EINVAL; |
243 | } | 244 | } |
244 | mutex_unlock(&inode_info->lower_file_mutex); | 245 | mutex_unlock(&inode_info->lower_file_mutex); |
245 | for (i = 0; i < size; i += PAGE_CACHE_SIZE) { | ||
246 | struct page *data_page; | ||
247 | |||
248 | data_page = virt_to_page(data + i); | ||
249 | flush_dcache_page(data_page); | ||
250 | if (rc) | ||
251 | ClearPageUptodate(data_page); | ||
252 | else | ||
253 | SetPageUptodate(data_page); | ||
254 | } | ||
255 | return rc; | 246 | return rc; |
256 | } | 247 | } |
257 | 248 | ||
@@ -283,6 +274,7 @@ int ecryptfs_read_lower_page_segment(struct page *page_for_ecryptfs, | |||
283 | virt = kmap(page_for_ecryptfs); | 274 | virt = kmap(page_for_ecryptfs); |
284 | rc = ecryptfs_read_lower(virt, offset, size, ecryptfs_inode); | 275 | rc = ecryptfs_read_lower(virt, offset, size, ecryptfs_inode); |
285 | kunmap(page_for_ecryptfs); | 276 | kunmap(page_for_ecryptfs); |
277 | flush_dcache_page(page_for_ecryptfs); | ||
286 | return rc; | 278 | return rc; |
287 | } | 279 | } |
288 | 280 | ||
@@ -331,8 +323,8 @@ int ecryptfs_read(char *data, loff_t offset, size_t size, | |||
331 | 323 | ||
332 | if (num_bytes > total_remaining_bytes) | 324 | if (num_bytes > total_remaining_bytes) |
333 | num_bytes = total_remaining_bytes; | 325 | num_bytes = total_remaining_bytes; |
334 | ecryptfs_page = ecryptfs_get1page(ecryptfs_file, | 326 | ecryptfs_page = ecryptfs_get_locked_page(ecryptfs_file, |
335 | ecryptfs_page_idx); | 327 | ecryptfs_page_idx); |
336 | if (IS_ERR(ecryptfs_page)) { | 328 | if (IS_ERR(ecryptfs_page)) { |
337 | rc = PTR_ERR(ecryptfs_page); | 329 | rc = PTR_ERR(ecryptfs_page); |
338 | printk(KERN_ERR "%s: Error getting page at " | 330 | printk(KERN_ERR "%s: Error getting page at " |
@@ -345,6 +337,7 @@ int ecryptfs_read(char *data, loff_t offset, size_t size, | |||
345 | if (rc) { | 337 | if (rc) { |
346 | printk(KERN_ERR "%s: Error decrypting " | 338 | printk(KERN_ERR "%s: Error decrypting " |
347 | "page; rc = [%d]\n", __FUNCTION__, rc); | 339 | "page; rc = [%d]\n", __FUNCTION__, rc); |
340 | ClearPageUptodate(ecryptfs_page); | ||
348 | page_cache_release(ecryptfs_page); | 341 | page_cache_release(ecryptfs_page); |
349 | goto out; | 342 | goto out; |
350 | } | 343 | } |
@@ -353,6 +346,9 @@ int ecryptfs_read(char *data, loff_t offset, size_t size, | |||
353 | ((char *)ecryptfs_page_virt + start_offset_in_page), | 346 | ((char *)ecryptfs_page_virt + start_offset_in_page), |
354 | num_bytes); | 347 | num_bytes); |
355 | kunmap_atomic(ecryptfs_page_virt, KM_USER0); | 348 | kunmap_atomic(ecryptfs_page_virt, KM_USER0); |
349 | flush_dcache_page(ecryptfs_page); | ||
350 | SetPageUptodate(ecryptfs_page); | ||
351 | unlock_page(ecryptfs_page); | ||
356 | page_cache_release(ecryptfs_page); | 352 | page_cache_release(ecryptfs_page); |
357 | pos += num_bytes; | 353 | pos += num_bytes; |
358 | data_offset += num_bytes; | 354 | data_offset += num_bytes; |