[RFC,3/5] files: Add new argument to expand_files()

Submitted by Kirill Tkhai on Jan. 12, 2018, 3:46 p.m.

Details

Message ID 151577199252.11063.9810222632587706627.stgit@localhost.localdomain
State New
Series "Shrink big fdtable on criu restore"
Headers show

Commit Message

Kirill Tkhai Jan. 12, 2018, 3:46 p.m.
Add argument "shrink" to the functions.
This is refactoring, which will be used
in next patches.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 fs/file.c |   16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

Patch hide | download patch | download mbox

diff --git a/fs/file.c b/fs/file.c
index 05ff3c5a6ec8..9743283200e0 100644
--- a/fs/file.c
+++ b/fs/file.c
@@ -65,7 +65,7 @@  static void free_fdtable_rcu(struct rcu_head *rcu)
  * Expand the fdset in the files_struct.  Called with the files spinlock
  * held for write.
  */
-static void copy_fdtable(struct fdtable *nfdt, struct fdtable *ofdt)
+static void copy_fdtable(struct fdtable *nfdt, struct fdtable *ofdt, bool shrink)
 {
 	unsigned int cpy, set;
 
@@ -144,7 +144,7 @@  static struct fdtable * alloc_fdtable(unsigned int nr)
  * Return <0 error code on error; 1 on successful completion.
  * The files->file_lock should be held on entry, and will be held on exit.
  */
-static int expand_fdtable(struct files_struct *files, int nr)
+static int expand_fdtable(struct files_struct *files, int nr, bool shrink)
 	__releases(files->file_lock)
 	__acquires(files->file_lock)
 {
@@ -172,7 +172,7 @@  static int expand_fdtable(struct files_struct *files, int nr)
 	}
 	cur_fdt = files_fdtable(files);
 	BUG_ON(nr < cur_fdt->max_fds);
-	copy_fdtable(new_fdt, cur_fdt);
+	copy_fdtable(new_fdt, cur_fdt, shrink);
 	rcu_assign_pointer(files->fdt, new_fdt);
 	if (cur_fdt != &files->fdtab)
 		call_rcu(&cur_fdt->rcu, free_fdtable_rcu);
@@ -189,7 +189,7 @@  static int expand_fdtable(struct files_struct *files, int nr)
  * expanded and execution may have blocked.
  * The files->file_lock should be held on entry, and will be held on exit.
  */
-static int expand_files(struct files_struct *files, int nr)
+static int expand_files(struct files_struct *files, int nr, bool shrink)
 	__releases(files->file_lock)
 	__acquires(files->file_lock)
 {
@@ -217,7 +217,7 @@  static int expand_files(struct files_struct *files, int nr)
 
 	/* All good, so we try */
 	files->resize_in_progress = true;
-	expanded = expand_fdtable(files, nr);
+	expanded = expand_fdtable(files, nr, shrink);
 	files->resize_in_progress = false;
 
 	wake_up_all(&files->resize_wait);
@@ -499,7 +499,7 @@  int __alloc_fd(struct files_struct *files,
 	if (fd >= end)
 		goto out;
 
-	error = expand_files(files, fd);
+	error = expand_files(files, fd, false);
 	if (error < 0)
 		goto out;
 
@@ -860,7 +860,7 @@  int replace_fd(unsigned fd, struct file *file, unsigned flags)
 		return -EBADF;
 
 	spin_lock(&files->file_lock);
-	err = expand_files(files, fd);
+	err = expand_files(files, fd, false);
 	if (unlikely(err < 0))
 		goto out_unlock;
 	return do_dup2(files, file, fd, flags);
@@ -886,7 +886,7 @@  SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
 		return -EBADF;
 
 	spin_lock(&files->file_lock);
-	err = expand_files(files, newfd);
+	err = expand_files(files, newfd, false);
 	file = fcheck(oldfd);
 	if (unlikely(!file))
 		goto Ebadf;