From 4309093ecb841bbd27fcd23525dd41b9a6b437ea Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Wed, 18 Jan 2023 18:30:25 +0100 Subject: sysv: don't flush page immediately for DIRSYNC directories We do not need to writeout modified directory blocks immediately when modifying them while the page is locked. It is enough to do the flush somewhat later which has the added benefit that inode times can be flushed as well. It also allows us to stop depending on write_one_page() function. Ported from an ext2 patch by Jan Kara. Signed-off-by: Christoph Hellwig Signed-off-by: Al Viro --- fs/sysv/dir.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'fs') diff --git a/fs/sysv/dir.c b/fs/sysv/dir.c index 88e38cd8f5c9..16730795a621 100644 --- a/fs/sysv/dir.c +++ b/fs/sysv/dir.c @@ -34,21 +34,26 @@ static inline void dir_put_page(struct page *page) put_page(page); } -static int dir_commit_chunk(struct page *page, loff_t pos, unsigned len) +static void dir_commit_chunk(struct page *page, loff_t pos, unsigned len) { struct address_space *mapping = page->mapping; struct inode *dir = mapping->host; - int err = 0; block_write_end(NULL, mapping, pos, len, len, page, NULL); if (pos+len > dir->i_size) { i_size_write(dir, pos+len); mark_inode_dirty(dir); } - if (IS_DIRSYNC(dir)) - err = write_one_page(page); - else - unlock_page(page); + unlock_page(page); +} + +static int sysv_handle_dirsync(struct inode *dir) +{ + int err; + + err = filemap_write_and_wait(dir->i_mapping); + if (!err) + err = sync_inode_metadata(dir, 1); return err; } @@ -215,9 +220,10 @@ got_it: memcpy (de->name, name, namelen); memset (de->name + namelen, 0, SYSV_DIRSIZE - namelen - 2); de->inode = cpu_to_fs16(SYSV_SB(inode->i_sb), inode->i_ino); - err = dir_commit_chunk(page, pos, SYSV_DIRSIZE); + dir_commit_chunk(page, pos, SYSV_DIRSIZE); dir->i_mtime = dir->i_ctime = current_time(dir); mark_inode_dirty(dir); + err = sysv_handle_dirsync(dir); out_page: dir_put_page(page); out: @@ -238,11 +244,11 @@ int sysv_delete_entry(struct sysv_dir_entry *de, struct page *page) err = sysv_prepare_chunk(page, pos, SYSV_DIRSIZE); BUG_ON(err); de->inode = 0; - err = dir_commit_chunk(page, pos, SYSV_DIRSIZE); + dir_commit_chunk(page, pos, SYSV_DIRSIZE); dir_put_page(page); inode->i_ctime = inode->i_mtime = current_time(inode); mark_inode_dirty(inode); - return err; + return sysv_handle_dirsync(inode); } int sysv_make_empty(struct inode *inode, struct inode *dir) @@ -272,7 +278,8 @@ int sysv_make_empty(struct inode *inode, struct inode *dir) strcpy(de->name,".."); kunmap(page); - err = dir_commit_chunk(page, 0, 2 * SYSV_DIRSIZE); + dir_commit_chunk(page, 0, 2 * SYSV_DIRSIZE); + err = sysv_handle_dirsync(inode); fail: put_page(page); return err; @@ -336,10 +343,11 @@ void sysv_set_link(struct sysv_dir_entry *de, struct page *page, err = sysv_prepare_chunk(page, pos, SYSV_DIRSIZE); BUG_ON(err); de->inode = cpu_to_fs16(SYSV_SB(inode->i_sb), inode->i_ino); - err = dir_commit_chunk(page, pos, SYSV_DIRSIZE); + dir_commit_chunk(page, pos, SYSV_DIRSIZE); dir_put_page(page); dir->i_mtime = dir->i_ctime = current_time(dir); mark_inode_dirty(dir); + sysv_handle_dirsync(inode); } struct sysv_dir_entry * sysv_dotdot (struct inode *dir, struct page **p) -- cgit v1.2.3-58-ga151 From 4bb1a1375ac33950385d17321c546aeb520ba152 Mon Sep 17 00:00:00 2001 From: "Fabio M. De Francesco" Date: Thu, 19 Jan 2023 16:32:29 +0100 Subject: fs/sysv: Use the offset_in_page() helper Use the offset_in_page() helper because it is more suitable than doing explicit subtractions between pointers to directory entries and kernel virtual addresses of mapped pages. Cc: Ira Weiny Suggested-by: Al Viro Signed-off-by: Fabio M. De Francesco Signed-off-by: Al Viro --- fs/sysv/dir.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'fs') diff --git a/fs/sysv/dir.c b/fs/sysv/dir.c index 16730795a621..0edd18e1d376 100644 --- a/fs/sysv/dir.c +++ b/fs/sysv/dir.c @@ -211,8 +211,7 @@ int sysv_add_link(struct dentry *dentry, struct inode *inode) return -EINVAL; got_it: - pos = page_offset(page) + - (char*)de - (char*)page_address(page); + pos = page_offset(page) + offset_in_page(de); lock_page(page); err = sysv_prepare_chunk(page, pos, SYSV_DIRSIZE); if (err) @@ -236,8 +235,7 @@ out_unlock: int sysv_delete_entry(struct sysv_dir_entry *de, struct page *page) { struct inode *inode = page->mapping->host; - char *kaddr = (char*)page_address(page); - loff_t pos = page_offset(page) + (char *)de - kaddr; + loff_t pos = page_offset(page) + offset_in_page(de); int err; lock_page(page); @@ -335,8 +333,7 @@ void sysv_set_link(struct sysv_dir_entry *de, struct page *page, struct inode *inode) { struct inode *dir = page->mapping->host; - loff_t pos = page_offset(page) + - (char *)de-(char*)page_address(page); + loff_t pos = page_offset(page) + offset_in_page(de); int err; lock_page(page); -- cgit v1.2.3-58-ga151 From 8dd6c7b2944ce349f06db763d7a2a90a0b83ba0d Mon Sep 17 00:00:00 2001 From: "Fabio M. De Francesco" Date: Thu, 19 Jan 2023 16:32:30 +0100 Subject: fs/sysv: Change the signature of dir_get_page() Change the signature of dir_get_page() in order to prepare this function to the conversion to the use of kmap_local_page(). Change also those call sites which are required to adjust to the new signature. Cc: Ira Weiny Suggested-by: Al Viro Signed-off-by: Fabio M. De Francesco Signed-off-by: Al Viro --- fs/sysv/dir.c | 53 ++++++++++++++++++++++++----------------------------- 1 file changed, 24 insertions(+), 29 deletions(-) (limited to 'fs') diff --git a/fs/sysv/dir.c b/fs/sysv/dir.c index 0edd18e1d376..ad334c8ef7b1 100644 --- a/fs/sysv/dir.c +++ b/fs/sysv/dir.c @@ -57,13 +57,15 @@ static int sysv_handle_dirsync(struct inode *dir) return err; } -static struct page * dir_get_page(struct inode *dir, unsigned long n) +static void *dir_get_page(struct inode *dir, unsigned long n, struct page **p) { struct address_space *mapping = dir->i_mapping; struct page *page = read_mapping_page(mapping, n, NULL); - if (!IS_ERR(page)) - kmap(page); - return page; + if (IS_ERR(page)) + return ERR_CAST(page); + kmap(page); + *p = page; + return page_address(page); } static int sysv_readdir(struct file *file, struct dir_context *ctx) @@ -85,11 +87,11 @@ static int sysv_readdir(struct file *file, struct dir_context *ctx) for ( ; n < npages; n++, offset = 0) { char *kaddr, *limit; struct sysv_dir_entry *de; - struct page *page = dir_get_page(inode, n); + struct page *page; - if (IS_ERR(page)) + kaddr = dir_get_page(inode, n, &page); + if (IS_ERR(kaddr)) continue; - kaddr = (char *)page_address(page); de = (struct sysv_dir_entry *)(kaddr+offset); limit = kaddr + PAGE_SIZE - SYSV_DIRSIZE; for ( ;(char*)de <= limit; de++, ctx->pos += sizeof(*de)) { @@ -147,11 +149,10 @@ struct sysv_dir_entry *sysv_find_entry(struct dentry *dentry, struct page **res_ n = start; do { - char *kaddr; - page = dir_get_page(dir, n); - if (!IS_ERR(page)) { - kaddr = (char*)page_address(page); - de = (struct sysv_dir_entry *) kaddr; + char *kaddr = dir_get_page(dir, n, &page); + + if (!IS_ERR(kaddr)) { + de = (struct sysv_dir_entry *)kaddr; kaddr += PAGE_SIZE - SYSV_DIRSIZE; for ( ; (char *) de <= kaddr ; de++) { if (!de->inode) @@ -190,11 +191,9 @@ int sysv_add_link(struct dentry *dentry, struct inode *inode) /* We take care of directory expansion in the same loop */ for (n = 0; n <= npages; n++) { - page = dir_get_page(dir, n); - err = PTR_ERR(page); - if (IS_ERR(page)) - goto out; - kaddr = (char*)page_address(page); + kaddr = dir_get_page(dir, n, &page); + if (IS_ERR(kaddr)) + return PTR_ERR(kaddr); de = (struct sysv_dir_entry *)kaddr; kaddr += PAGE_SIZE - SYSV_DIRSIZE; while ((char *)de <= kaddr) { @@ -225,7 +224,6 @@ got_it: err = sysv_handle_dirsync(dir); out_page: dir_put_page(page); -out: return err; out_unlock: unlock_page(page); @@ -295,12 +293,11 @@ int sysv_empty_dir(struct inode * inode) for (i = 0; i < npages; i++) { char *kaddr; struct sysv_dir_entry * de; - page = dir_get_page(inode, i); - if (IS_ERR(page)) + kaddr = dir_get_page(inode, i, &page); + if (IS_ERR(kaddr)) continue; - kaddr = (char *)page_address(page); de = (struct sysv_dir_entry *)kaddr; kaddr += PAGE_SIZE-SYSV_DIRSIZE; @@ -347,16 +344,14 @@ void sysv_set_link(struct sysv_dir_entry *de, struct page *page, sysv_handle_dirsync(inode); } -struct sysv_dir_entry * sysv_dotdot (struct inode *dir, struct page **p) +struct sysv_dir_entry *sysv_dotdot(struct inode *dir, struct page **p) { - struct page *page = dir_get_page(dir, 0); - struct sysv_dir_entry *de = NULL; + struct sysv_dir_entry *de = dir_get_page(dir, 0, p); - if (!IS_ERR(page)) { - de = (struct sysv_dir_entry*) page_address(page) + 1; - *p = page; - } - return de; + if (IS_ERR(de)) + return NULL; + /* ".." is the second directory entry */ + return de + 1; } ino_t sysv_inode_by_name(struct dentry *dentry) -- cgit v1.2.3-58-ga151 From c26ddc49c9080975cc03cf3bd6917c3fb37d808b Mon Sep 17 00:00:00 2001 From: "Fabio M. De Francesco" Date: Thu, 19 Jan 2023 16:32:31 +0100 Subject: fs/sysv: Use dir_put_page() in sysv_rename() Use the dir_put_page() helper in sysv_rename() instead of open-coding two kunmap() + put_page(). Cc: Al Viro Suggested-by: Ira Weiny Signed-off-by: Fabio M. De Francesco Signed-off-by: Al Viro --- fs/sysv/dir.c | 2 +- fs/sysv/namei.c | 9 +++------ fs/sysv/sysv.h | 1 + 3 files changed, 5 insertions(+), 7 deletions(-) (limited to 'fs') diff --git a/fs/sysv/dir.c b/fs/sysv/dir.c index ad334c8ef7b1..6b402e685f1e 100644 --- a/fs/sysv/dir.c +++ b/fs/sysv/dir.c @@ -28,7 +28,7 @@ const struct file_operations sysv_dir_operations = { .fsync = generic_file_fsync, }; -static inline void dir_put_page(struct page *page) +inline void dir_put_page(struct page *page) { kunmap(page); put_page(page); diff --git a/fs/sysv/namei.c b/fs/sysv/namei.c index b2e6abc06a2d..981c1d76f342 100644 --- a/fs/sysv/namei.c +++ b/fs/sysv/namei.c @@ -250,13 +250,10 @@ static int sysv_rename(struct user_namespace *mnt_userns, struct inode *old_dir, return 0; out_dir: - if (dir_de) { - kunmap(dir_page); - put_page(dir_page); - } + if (dir_de) + dir_put_page(dir_page); out_old: - kunmap(old_page); - put_page(old_page); + dir_put_page(old_page); out: return err; } diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h index 99ddf033da4f..b250ac1dd348 100644 --- a/fs/sysv/sysv.h +++ b/fs/sysv/sysv.h @@ -148,6 +148,7 @@ extern void sysv_destroy_icache(void); /* dir.c */ +extern void dir_put_page(struct page *page); extern struct sysv_dir_entry *sysv_find_entry(struct dentry *, struct page **); extern int sysv_add_link(struct dentry *, struct inode *); extern int sysv_delete_entry(struct sysv_dir_entry *, struct page *); -- cgit v1.2.3-58-ga151 From 83005276d383387fec7e18c7a36daade579a23a7 Mon Sep 17 00:00:00 2001 From: "Fabio M. De Francesco" Date: Thu, 19 Jan 2023 16:32:32 +0100 Subject: fs/sysv: Replace kmap() with kmap_local_page() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit kmap() is being deprecated in favor of kmap_local_page(). There are two main problems with kmap(): (1) It comes with an overhead as the mapping space is restricted and protected by a global lock for synchronization and (2) it also requires global TLB invalidation when the kmap’s pool wraps and it might block when the mapping space is fully utilized until a slot becomes available. With kmap_local_page() the mappings are per thread, CPU local, can take page faults, and can be called from any context (including interrupts). It is faster than kmap() in kernels with HIGHMEM enabled. Furthermore, the tasks can be preempted and, when they are scheduled to run again, the kernel virtual addresses are restored and still valid. Since kmap_local_page() would not break the strict rules of local mappings (i.e., the thread locality and the stack based nesting), this function can be easily and safely replace the deprecated API. Therefore, replace kmap() with kmap_local_page() in fs/sysv. kunmap_local() requires the mapping address, so return that address from dir_get_page() to be used in dir_put_page(). Suggested-by: Al Viro Suggested-by: Ira Weiny Signed-off-by: Fabio M. De Francesco Signed-off-by: Al Viro --- fs/sysv/dir.c | 56 ++++++++++++++++++++++++++++++++++++-------------------- fs/sysv/namei.c | 4 ++-- fs/sysv/sysv.h | 2 +- 3 files changed, 39 insertions(+), 23 deletions(-) (limited to 'fs') diff --git a/fs/sysv/dir.c b/fs/sysv/dir.c index 6b402e685f1e..3ed98d66b152 100644 --- a/fs/sysv/dir.c +++ b/fs/sysv/dir.c @@ -28,9 +28,9 @@ const struct file_operations sysv_dir_operations = { .fsync = generic_file_fsync, }; -inline void dir_put_page(struct page *page) +inline void dir_put_page(struct page *page, void *page_addr) { - kunmap(page); + kunmap_local((void *)((unsigned long)page_addr & PAGE_MASK)); put_page(page); } @@ -57,15 +57,21 @@ static int sysv_handle_dirsync(struct inode *dir) return err; } +/* + * Calls to dir_get_page()/dir_put_page() must be nested according to the + * rules documented in mm/highmem.rst. + * + * NOTE: sysv_find_entry() and sysv_dotdot() act as calls to dir_get_page() + * and must be treated accordingly for nesting purposes. + */ static void *dir_get_page(struct inode *dir, unsigned long n, struct page **p) { struct address_space *mapping = dir->i_mapping; struct page *page = read_mapping_page(mapping, n, NULL); if (IS_ERR(page)) return ERR_CAST(page); - kmap(page); *p = page; - return page_address(page); + return kmap_local_page(page); } static int sysv_readdir(struct file *file, struct dir_context *ctx) @@ -103,11 +109,11 @@ static int sysv_readdir(struct file *file, struct dir_context *ctx) if (!dir_emit(ctx, name, strnlen(name,SYSV_NAMELEN), fs16_to_cpu(SYSV_SB(sb), de->inode), DT_UNKNOWN)) { - dir_put_page(page); + dir_put_page(page, kaddr); return 0; } } - dir_put_page(page); + dir_put_page(page, kaddr); } return 0; } @@ -130,6 +136,11 @@ static inline int namecompare(int len, int maxlen, * returns the cache buffer in which the entry was found, and the entry * itself (as a parameter - res_dir). It does NOT read the inode of the * entry - you'll have to do that yourself if you want to. + * + * On Success dir_put_page() should be called on *res_page. + * + * sysv_find_entry() acts as a call to dir_get_page() and must be treated + * accordingly for nesting purposes. */ struct sysv_dir_entry *sysv_find_entry(struct dentry *dentry, struct page **res_page) { @@ -161,7 +172,7 @@ struct sysv_dir_entry *sysv_find_entry(struct dentry *dentry, struct page **res_ name, de->name)) goto found; } - dir_put_page(page); + dir_put_page(page, kaddr); } if (++n >= npages) @@ -204,7 +215,7 @@ int sysv_add_link(struct dentry *dentry, struct inode *inode) goto out_page; de++; } - dir_put_page(page); + dir_put_page(page, kaddr); } BUG(); return -EINVAL; @@ -223,7 +234,7 @@ got_it: mark_inode_dirty(dir); err = sysv_handle_dirsync(dir); out_page: - dir_put_page(page); + dir_put_page(page, kaddr); return err; out_unlock: unlock_page(page); @@ -241,7 +252,7 @@ int sysv_delete_entry(struct sysv_dir_entry *de, struct page *page) BUG_ON(err); de->inode = 0; dir_commit_chunk(page, pos, SYSV_DIRSIZE); - dir_put_page(page); + dir_put_page(page, de); inode->i_ctime = inode->i_mtime = current_time(inode); mark_inode_dirty(inode); return sysv_handle_dirsync(inode); @@ -261,9 +272,7 @@ int sysv_make_empty(struct inode *inode, struct inode *dir) unlock_page(page); goto fail; } - kmap(page); - - base = (char*)page_address(page); + base = kmap_local_page(page); memset(base, 0, PAGE_SIZE); de = (struct sysv_dir_entry *) base; @@ -273,7 +282,7 @@ int sysv_make_empty(struct inode *inode, struct inode *dir) de->inode = cpu_to_fs16(SYSV_SB(inode->i_sb), dir->i_ino); strcpy(de->name,".."); - kunmap(page); + kunmap_local(base); dir_commit_chunk(page, 0, 2 * SYSV_DIRSIZE); err = sysv_handle_dirsync(inode); fail: @@ -289,10 +298,10 @@ int sysv_empty_dir(struct inode * inode) struct super_block *sb = inode->i_sb; struct page *page = NULL; unsigned long i, npages = dir_pages(inode); + char *kaddr; for (i = 0; i < npages; i++) { - char *kaddr; - struct sysv_dir_entry * de; + struct sysv_dir_entry *de; kaddr = dir_get_page(inode, i, &page); if (IS_ERR(kaddr)) @@ -316,12 +325,12 @@ int sysv_empty_dir(struct inode * inode) if (de->name[1] != '.' || de->name[2]) goto not_empty; } - dir_put_page(page); + dir_put_page(page, kaddr); } return 1; not_empty: - dir_put_page(page); + dir_put_page(page, kaddr); return 0; } @@ -338,12 +347,19 @@ void sysv_set_link(struct sysv_dir_entry *de, struct page *page, BUG_ON(err); de->inode = cpu_to_fs16(SYSV_SB(inode->i_sb), inode->i_ino); dir_commit_chunk(page, pos, SYSV_DIRSIZE); - dir_put_page(page); + dir_put_page(page, de); dir->i_mtime = dir->i_ctime = current_time(dir); mark_inode_dirty(dir); sysv_handle_dirsync(inode); } +/* + * Calls to dir_get_page()/dir_put_page() must be nested according to the + * rules documented in mm/highmem.rst. + * + * sysv_dotdot() acts as a call to dir_get_page() and must be treated + * accordingly for nesting purposes. + */ struct sysv_dir_entry *sysv_dotdot(struct inode *dir, struct page **p) { struct sysv_dir_entry *de = dir_get_page(dir, 0, p); @@ -362,7 +378,7 @@ ino_t sysv_inode_by_name(struct dentry *dentry) if (de) { res = fs16_to_cpu(SYSV_SB(dentry->d_sb), de->inode); - dir_put_page(page); + dir_put_page(page, de); } return res; } diff --git a/fs/sysv/namei.c b/fs/sysv/namei.c index 981c1d76f342..371cf9012052 100644 --- a/fs/sysv/namei.c +++ b/fs/sysv/namei.c @@ -251,9 +251,9 @@ static int sysv_rename(struct user_namespace *mnt_userns, struct inode *old_dir, out_dir: if (dir_de) - dir_put_page(dir_page); + dir_put_page(dir_page, dir_de); out_old: - dir_put_page(old_page); + dir_put_page(old_page, old_de); out: return err; } diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h index b250ac1dd348..50f19bfd8d10 100644 --- a/fs/sysv/sysv.h +++ b/fs/sysv/sysv.h @@ -148,7 +148,7 @@ extern void sysv_destroy_icache(void); /* dir.c */ -extern void dir_put_page(struct page *page); +extern void dir_put_page(struct page *page, void *vaddr); extern struct sysv_dir_entry *sysv_find_entry(struct dentry *, struct page **); extern int sysv_add_link(struct dentry *, struct inode *); extern int sysv_delete_entry(struct sysv_dir_entry *, struct page *); -- cgit v1.2.3-58-ga151 From abb7c742397324f8676c5b622effdce911cd52e3 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Thu, 19 Jan 2023 20:05:43 -0500 Subject: sysv: fix handling of delete_entry and set_link failures similar to minixfs series - make sysv_set_link() report failures, lift dir_put_page() into the callers of sysv_set_link() and sysv_delete_entry(), make sysv_rename() handle failures in both. Signed-off-by: Al Viro --- fs/sysv/dir.c | 16 ++++++++++------ fs/sysv/namei.c | 33 +++++++++++++++++++-------------- fs/sysv/sysv.h | 2 +- 3 files changed, 30 insertions(+), 21 deletions(-) (limited to 'fs') diff --git a/fs/sysv/dir.c b/fs/sysv/dir.c index 3ed98d66b152..999bceb99974 100644 --- a/fs/sysv/dir.c +++ b/fs/sysv/dir.c @@ -249,10 +249,12 @@ int sysv_delete_entry(struct sysv_dir_entry *de, struct page *page) lock_page(page); err = sysv_prepare_chunk(page, pos, SYSV_DIRSIZE); - BUG_ON(err); + if (err) { + unlock_page(page); + return err; + } de->inode = 0; dir_commit_chunk(page, pos, SYSV_DIRSIZE); - dir_put_page(page, de); inode->i_ctime = inode->i_mtime = current_time(inode); mark_inode_dirty(inode); return sysv_handle_dirsync(inode); @@ -335,7 +337,7 @@ not_empty: } /* Releases the page */ -void sysv_set_link(struct sysv_dir_entry *de, struct page *page, +int sysv_set_link(struct sysv_dir_entry *de, struct page *page, struct inode *inode) { struct inode *dir = page->mapping->host; @@ -344,13 +346,15 @@ void sysv_set_link(struct sysv_dir_entry *de, struct page *page, lock_page(page); err = sysv_prepare_chunk(page, pos, SYSV_DIRSIZE); - BUG_ON(err); + if (err) { + unlock_page(page); + return err; + } de->inode = cpu_to_fs16(SYSV_SB(inode->i_sb), inode->i_ino); dir_commit_chunk(page, pos, SYSV_DIRSIZE); - dir_put_page(page, de); dir->i_mtime = dir->i_ctime = current_time(dir); mark_inode_dirty(dir); - sysv_handle_dirsync(inode); + return sysv_handle_dirsync(inode); } /* diff --git a/fs/sysv/namei.c b/fs/sysv/namei.c index 371cf9012052..1bfe788851a9 100644 --- a/fs/sysv/namei.c +++ b/fs/sysv/namei.c @@ -153,19 +153,18 @@ static int sysv_unlink(struct inode * dir, struct dentry * dentry) struct inode * inode = d_inode(dentry); struct page * page; struct sysv_dir_entry * de; - int err = -ENOENT; + int err; de = sysv_find_entry(dentry, &page); if (!de) - goto out; - - err = sysv_delete_entry (de, page); - if (err) - goto out; + return -ENOENT; - inode->i_ctime = dir->i_ctime; - inode_dec_link_count(inode); -out: + err = sysv_delete_entry(de, page); + if (!err) { + inode->i_ctime = dir->i_ctime; + inode_dec_link_count(inode); + } + dir_put_page(page, de); return err; } @@ -227,7 +226,10 @@ static int sysv_rename(struct user_namespace *mnt_userns, struct inode *old_dir, new_de = sysv_find_entry(new_dentry, &new_page); if (!new_de) goto out_dir; - sysv_set_link(new_de, new_page, old_inode); + err = sysv_set_link(new_de, new_page, old_inode); + dir_put_page(new_page, new_de); + if (err) + goto out_dir; new_inode->i_ctime = current_time(new_inode); if (dir_de) drop_nlink(new_inode); @@ -240,14 +242,17 @@ static int sysv_rename(struct user_namespace *mnt_userns, struct inode *old_dir, inode_inc_link_count(new_dir); } - sysv_delete_entry(old_de, old_page); + err = sysv_delete_entry(old_de, old_page); + if (err) + goto out_dir; + mark_inode_dirty(old_inode); if (dir_de) { - sysv_set_link(dir_de, dir_page, new_dir); - inode_dec_link_count(old_dir); + err = sysv_set_link(dir_de, dir_page, new_dir); + if (!err) + inode_dec_link_count(old_dir); } - return 0; out_dir: if (dir_de) diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h index 50f19bfd8d10..7d900dce713d 100644 --- a/fs/sysv/sysv.h +++ b/fs/sysv/sysv.h @@ -154,7 +154,7 @@ extern int sysv_add_link(struct dentry *, struct inode *); extern int sysv_delete_entry(struct sysv_dir_entry *, struct page *); extern int sysv_make_empty(struct inode *, struct inode *); extern int sysv_empty_dir(struct inode *); -extern void sysv_set_link(struct sysv_dir_entry *, struct page *, +extern int sysv_set_link(struct sysv_dir_entry *, struct page *, struct inode *); extern struct sysv_dir_entry *sysv_dotdot(struct inode *, struct page **); extern ino_t sysv_inode_by_name(struct dentry *); -- cgit v1.2.3-58-ga151