* [PATCH -mm 9/9] unshare system call : allow unsharing of files
@ 2005-12-13 13:43 JANAK DESAI
0 siblings, 0 replies; 3+ messages in thread
From: JANAK DESAI @ 2005-12-13 13:43 UTC (permalink / raw)
To: viro, chrisw, dwmw2, jamie, serue, mingo, linuxram, jmorris, sds, janak
Cc: akpm, linux-kernel
[PATCH -mm 9/9] unshare system call: allow unsharing of files
fork.c | 82 ++++++++++++++++++++++++++++++++++++++++++-----------------------
1 files changed, 53 insertions(+), 29 deletions(-)
diff -Naurp 2.6.15-rc5-mm2+patch/kernel/fork.c 2.6.15-rc5-mm2+patch9/kernel/fork.c
--- 2.6.15-rc5-mm2+patch/kernel/fork.c 2005-12-12 19:31:48.000000000 +0000
+++ 2.6.15-rc5-mm2+patch9/kernel/fork.c 2005-12-12 22:30:50.000000000 +0000
@@ -596,32 +596,19 @@ out:
return newf;
}
-static int copy_files(unsigned long clone_flags, struct task_struct * tsk)
+/*
+ * Allocate a new files structure and copy contents from the
+ * files structure of the passed in task structure.
+ */
+static struct files_struct *dup_fd(struct task_struct *tsk, int *errorp)
{
struct files_struct *oldf, *newf;
struct file **old_fds, **new_fds;
- int open_files, size, i, error = 0, expand;
+ int open_files, size, i, expand;
struct fdtable *old_fdt, *new_fdt;
- /*
- * A background process may not have any files ...
- */
- oldf = current->files;
- if (!oldf)
- goto out;
+ oldf = tsk->files;
- if (clone_flags & CLONE_FILES) {
- atomic_inc(&oldf->count);
- goto out;
- }
-
- /*
- * Note: we may be using current for both targets (See exec.c)
- * This works because we cache current->files (old) as oldf. Don't
- * break this.
- */
- tsk->files = NULL;
- error = -ENOMEM;
newf = alloc_files();
if (!newf)
goto out;
@@ -650,9 +637,9 @@ static int copy_files(unsigned long clon
if (expand) {
spin_unlock(&oldf->file_lock);
spin_lock(&newf->file_lock);
- error = expand_files(newf, open_files-1);
+ *errorp = expand_files(newf, open_files-1);
spin_unlock(&newf->file_lock);
- if (error < 0)
+ if (*errorp < 0)
goto out_release;
new_fdt = files_fdtable(newf);
/*
@@ -701,10 +688,8 @@ static int copy_files(unsigned long clon
memset(&new_fdt->close_on_exec->fds_bits[start], 0, left);
}
- tsk->files = newf;
- error = 0;
out:
- return error;
+ return newf;
out_release:
free_fdset (new_fdt->close_on_exec, new_fdt->max_fdset);
@@ -714,6 +699,40 @@ out_release:
goto out;
}
+static int copy_files(unsigned long clone_flags, struct task_struct * tsk)
+{
+ struct files_struct *oldf, *newf;
+ int error = 0;
+
+ /*
+ * A background process may not have any files ...
+ */
+ oldf = current->files;
+ if (!oldf)
+ goto out;
+
+ if (clone_flags & CLONE_FILES) {
+ atomic_inc(&oldf->count);
+ goto out;
+ }
+
+ /*
+ * Note: we may be using current for both targets (See exec.c)
+ * This works because we cache current->files (old) as oldf. Don't
+ * break this.
+ */
+ tsk->files = NULL;
+ error = -ENOMEM;
+ newf = dup_fd(current, &error);
+ if (!newf)
+ goto out;
+
+ tsk->files = newf;
+ error = 0;
+out:
+ return error;
+}
+
/*
* Helper to unshare the files of the current task.
* We don't want to expose copy_files internals to
@@ -1437,15 +1456,20 @@ static int unshare_vm(unsigned long unsh
}
/*
- * Unsharing of files for tasks created with CLONE_FILES is not supported yet
+ * Unshare file descriptor table if it is being shared
*/
static int unshare_fd(unsigned long unshare_flags, struct files_struct **new_fdp)
{
- struct files_struct *fd = current->files;
+ struct files_struct *fd = current->files, *new_fd;
+ int error = 0;
if ((unshare_flags & CLONE_FILES) &&
- (fd && atomic_read(&fd->count) > 1))
- return -EINVAL;
+ (fd && atomic_read(&fd->count) > 1)) {
+ new_fd = dup_fd(current, &error);
+ if (!new_fd)
+ return error;
+ *new_fdp = new_fd;
+ }
return 0;
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH -mm 9/9] unshare system call: allow unsharing of files
@ 2005-12-13 22:54 JANAK DESAI
0 siblings, 0 replies; 3+ messages in thread
From: JANAK DESAI @ 2005-12-13 22:54 UTC (permalink / raw)
To: viro, chrisw, dwmw2, jamie, serue, mingo, linuxram, jmorris, sds, janak
Cc: akpm, linux-kernel
[PATCH -mm 9/9] unshare system call: allow unsharing of files
If the file descriptor structure is being shared, allocate a new one and
copy information from the current, shared, structure.
Changes since the first submission of this patch on 12/12/05:
- Removed an unnecessary local variable (12/13/05)
Signed-off-by: Janak Desai <janak@us.ibm.com>
---
fork.c | 79 +++++++++++++++++++++++++++++++++++++++++------------------------
1 files changed, 51 insertions(+), 28 deletions(-)
diff -Naurp 2.6.15-rc5-mm2+patch/kernel/fork.c 2.6.15-rc5-mm2+patch9/kernel/fork.c
--- 2.6.15-rc5-mm2+patch/kernel/fork.c 2005-12-13 18:38:26.000000000 +0000
+++ 2.6.15-rc5-mm2+patch9/kernel/fork.c 2005-12-13 19:42:30.000000000 +0000
@@ -596,32 +596,19 @@ out:
return newf;
}
-static int copy_files(unsigned long clone_flags, struct task_struct * tsk)
+/*
+ * Allocate a new files structure and copy contents from the
+ * files structure of the passed in task structure.
+ */
+static struct files_struct *dup_fd(struct task_struct *tsk, int *errorp)
{
struct files_struct *oldf, *newf;
struct file **old_fds, **new_fds;
- int open_files, size, i, error = 0, expand;
+ int open_files, size, i, expand;
struct fdtable *old_fdt, *new_fdt;
- /*
- * A background process may not have any files ...
- */
- oldf = current->files;
- if (!oldf)
- goto out;
+ oldf = tsk->files;
- if (clone_flags & CLONE_FILES) {
- atomic_inc(&oldf->count);
- goto out;
- }
-
- /*
- * Note: we may be using current for both targets (See exec.c)
- * This works because we cache current->files (old) as oldf. Don't
- * break this.
- */
- tsk->files = NULL;
- error = -ENOMEM;
newf = alloc_files();
if (!newf)
goto out;
@@ -650,9 +637,9 @@ static int copy_files(unsigned long clon
if (expand) {
spin_unlock(&oldf->file_lock);
spin_lock(&newf->file_lock);
- error = expand_files(newf, open_files-1);
+ *errorp = expand_files(newf, open_files-1);
spin_unlock(&newf->file_lock);
- if (error < 0)
+ if (*errorp < 0)
goto out_release;
new_fdt = files_fdtable(newf);
/*
@@ -701,10 +688,8 @@ static int copy_files(unsigned long clon
memset(&new_fdt->close_on_exec->fds_bits[start], 0, left);
}
- tsk->files = newf;
- error = 0;
out:
- return error;
+ return newf;
out_release:
free_fdset (new_fdt->close_on_exec, new_fdt->max_fdset);
@@ -714,6 +699,40 @@ out_release:
goto out;
}
+static int copy_files(unsigned long clone_flags, struct task_struct * tsk)
+{
+ struct files_struct *oldf, *newf;
+ int error = 0;
+
+ /*
+ * A background process may not have any files ...
+ */
+ oldf = current->files;
+ if (!oldf)
+ goto out;
+
+ if (clone_flags & CLONE_FILES) {
+ atomic_inc(&oldf->count);
+ goto out;
+ }
+
+ /*
+ * Note: we may be using current for both targets (See exec.c)
+ * This works because we cache current->files (old) as oldf. Don't
+ * break this.
+ */
+ tsk->files = NULL;
+ error = -ENOMEM;
+ newf = dup_fd(current, &error);
+ if (!newf)
+ goto out;
+
+ tsk->files = newf;
+ error = 0;
+out:
+ return error;
+}
+
/*
* Helper to unshare the files of the current task.
* We don't want to expose copy_files internals to
@@ -1437,15 +1456,19 @@ static int unshare_vm(unsigned long unsh
}
/*
- * Unsharing of files for tasks created with CLONE_FILES is not supported yet
+ * Unshare file descriptor table if it is being shared
*/
static int unshare_fd(unsigned long unshare_flags, struct files_struct **new_fdp)
{
struct files_struct *fd = current->files;
+ int error = 0;
if ((unshare_flags & CLONE_FILES) &&
- (fd && atomic_read(&fd->count) > 1))
- return -EINVAL;
+ (fd && atomic_read(&fd->count) > 1)) {
+ *new_fdp = dup_fd(current, &error);
+ if (!*new_fdp)
+ return error;
+ }
return 0;
}
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH -mm 9/9] unshare system call : allow unsharing of files
@ 2005-12-13 3:00 JANAK DESAI
0 siblings, 0 replies; 3+ messages in thread
From: JANAK DESAI @ 2005-12-13 3:00 UTC (permalink / raw)
To: viro, chrisw, dwmw2, jamie, serue, mingo, linuxram, jmorris, sds, janak
Cc: akpm, linux-kernel
[PATCH -mm 9/9] unshare system call: allow unsharing of files
fork.c | 82
++++++++++++++++++++++++++++++++++++++++++-----------------------
1 files changed, 53 insertions(+), 29 deletions(-)
diff -Naurp 2.6.15-rc5-mm2+patch/kernel/fork.c
2.6.15-rc5-mm2+patch9/kernel/fork.c
--- 2.6.15-rc5-mm2+patch/kernel/fork.c 2005-12-12 19:31:48.000000000
+0000
+++ 2.6.15-rc5-mm2+patch9/kernel/fork.c 2005-12-12 22:30:50.000000000
+0000
@@ -596,32 +596,19 @@ out:
return newf;
}
-static int copy_files(unsigned long clone_flags, struct task_struct *
tsk)
+/*
+ * Allocate a new files structure and copy contents from the
+ * files structure of the passed in task structure.
+ */
+static struct files_struct *dup_fd(struct task_struct *tsk, int
*errorp)
{
struct files_struct *oldf, *newf;
struct file **old_fds, **new_fds;
- int open_files, size, i, error = 0, expand;
+ int open_files, size, i, expand;
struct fdtable *old_fdt, *new_fdt;
- /*
- * A background process may not have any files ...
- */
- oldf = current->files;
- if (!oldf)
- goto out;
+ oldf = tsk->files;
- if (clone_flags & CLONE_FILES) {
- atomic_inc(&oldf->count);
- goto out;
- }
-
- /*
- * Note: we may be using current for both targets (See exec.c)
- * This works because we cache current->files (old) as oldf. Don't
- * break this.
- */
- tsk->files = NULL;
- error = -ENOMEM;
newf = alloc_files();
if (!newf)
goto out;
@@ -650,9 +637,9 @@ static int copy_files(unsigned long clon
if (expand) {
spin_unlock(&oldf->file_lock);
spin_lock(&newf->file_lock);
- error = expand_files(newf, open_files-1);
+ *errorp = expand_files(newf, open_files-1);
spin_unlock(&newf->file_lock);
- if (error < 0)
+ if (*errorp < 0)
goto out_release;
new_fdt = files_fdtable(newf);
/*
@@ -701,10 +688,8 @@ static int copy_files(unsigned long clon
memset(&new_fdt->close_on_exec->fds_bits[start], 0, left);
}
- tsk->files = newf;
- error = 0;
out:
- return error;
+ return newf;
out_release:
free_fdset (new_fdt->close_on_exec, new_fdt->max_fdset);
@@ -714,6 +699,40 @@ out_release:
goto out;
}
+static int copy_files(unsigned long clone_flags, struct task_struct *
tsk)
+{
+ struct files_struct *oldf, *newf;
+ int error = 0;
+
+ /*
+ * A background process may not have any files ...
+ */
+ oldf = current->files;
+ if (!oldf)
+ goto out;
+
+ if (clone_flags & CLONE_FILES) {
+ atomic_inc(&oldf->count);
+ goto out;
+ }
+
+ /*
+ * Note: we may be using current for both targets (See exec.c)
+ * This works because we cache current->files (old) as oldf. Don't
+ * break this.
+ */
+ tsk->files = NULL;
+ error = -ENOMEM;
+ newf = dup_fd(current, &error);
+ if (!newf)
+ goto out;
+
+ tsk->files = newf;
+ error = 0;
+out:
+ return error;
+}
+
/*
* Helper to unshare the files of the current task.
* We don't want to expose copy_files internals to
@@ -1437,15 +1456,20 @@ static int unshare_vm(unsigned long unsh
}
/*
- * Unsharing of files for tasks created with CLONE_FILES is not
supported yet
+ * Unshare file descriptor table if it is being shared
*/
static int unshare_fd(unsigned long unshare_flags, struct files_struct
**new_fdp)
{
- struct files_struct *fd = current->files;
+ struct files_struct *fd = current->files, *new_fd;
+ int error = 0;
if ((unshare_flags & CLONE_FILES) &&
- (fd && atomic_read(&fd->count) > 1))
- return -EINVAL;
+ (fd && atomic_read(&fd->count) > 1)) {
+ new_fd = dup_fd(current, &error);
+ if (!new_fd)
+ return error;
+ *new_fdp = new_fd;
+ }
return 0;
}
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2005-12-13 22:55 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-12-13 13:43 [PATCH -mm 9/9] unshare system call : allow unsharing of files JANAK DESAI
-- strict thread matches above, loose matches on Subject: below --
2005-12-13 22:54 [PATCH -mm 9/9] unshare system call: " JANAK DESAI
2005-12-13 3:00 [PATCH -mm 9/9] unshare system call : " JANAK DESAI
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.