aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAl Viro <viro@zeniv.linux.org.uk>2012-01-10 22:35:38 -0500
committerAl Viro <viro@zeniv.linux.org.uk>2012-01-11 00:20:12 -0500
commitd668dc56631da067540b2494d2a1f29ff7b5f15a (patch)
tree303ad17208838e8b9b1752f9427d55c84555f0f0
parent8753333266be67ff3a984ac1f6566d31c260bee4 (diff)
autofs4: deal with autofs4_write/autofs4_write races
Just serialize the actual writing of packets into pipe on a new mutex, independent from everything else in the locking hierarchy. As soon as something has started feeding a piece of packet into the pipe to daemon, we *want* everything else about to try the same to wait until we are done. Acked-by: Ian Kent <raven@themaw.net> Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r--fs/autofs4/autofs_i.h1
-rw-r--r--fs/autofs4/inode.c1
-rw-r--r--fs/autofs4/waitq.c9
3 files changed, 7 insertions, 4 deletions
diff --git a/fs/autofs4/autofs_i.h b/fs/autofs4/autofs_i.h
index 5869d4e974a9..d8d8e7ba6a1e 100644
--- a/fs/autofs4/autofs_i.h
+++ b/fs/autofs4/autofs_i.h
@@ -116,6 +116,7 @@ struct autofs_sb_info {
116 int needs_reghost; 116 int needs_reghost;
117 struct super_block *sb; 117 struct super_block *sb;
118 struct mutex wq_mutex; 118 struct mutex wq_mutex;
119 struct mutex pipe_mutex;
119 spinlock_t fs_lock; 120 spinlock_t fs_lock;
120 struct autofs_wait_queue *queues; /* Wait queue pointer */ 121 struct autofs_wait_queue *queues; /* Wait queue pointer */
121 spinlock_t lookup_lock; 122 spinlock_t lookup_lock;
diff --git a/fs/autofs4/inode.c b/fs/autofs4/inode.c
index 2ba44c79d548..e16980b00b8d 100644
--- a/fs/autofs4/inode.c
+++ b/fs/autofs4/inode.c
@@ -225,6 +225,7 @@ int autofs4_fill_super(struct super_block *s, void *data, int silent)
225 sbi->min_proto = 0; 225 sbi->min_proto = 0;
226 sbi->max_proto = 0; 226 sbi->max_proto = 0;
227 mutex_init(&sbi->wq_mutex); 227 mutex_init(&sbi->wq_mutex);
228 mutex_init(&sbi->pipe_mutex);
228 spin_lock_init(&sbi->fs_lock); 229 spin_lock_init(&sbi->fs_lock);
229 sbi->queues = NULL; 230 sbi->queues = NULL;
230 spin_lock_init(&sbi->lookup_lock); 231 spin_lock_init(&sbi->lookup_lock);
diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
index 9a0256da5d56..9ef5b2914407 100644
--- a/fs/autofs4/waitq.c
+++ b/fs/autofs4/waitq.c
@@ -56,26 +56,27 @@ void autofs4_catatonic_mode(struct autofs_sb_info *sbi)
56 mutex_unlock(&sbi->wq_mutex); 56 mutex_unlock(&sbi->wq_mutex);
57} 57}
58 58
59static int autofs4_write(struct file *file, const void *addr, int bytes) 59static int autofs4_write(struct autofs_sb_info *sbi,
60 struct file *file, const void *addr, int bytes)
60{ 61{
61 unsigned long sigpipe, flags; 62 unsigned long sigpipe, flags;
62 mm_segment_t fs; 63 mm_segment_t fs;
63 const char *data = (const char *)addr; 64 const char *data = (const char *)addr;
64 ssize_t wr = 0; 65 ssize_t wr = 0;
65 66
66 /** WARNING: this is not safe for writing more than PIPE_BUF bytes! **/
67
68 sigpipe = sigismember(&current->pending.signal, SIGPIPE); 67 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
69 68
70 /* Save pointer to user space and point back to kernel space */ 69 /* Save pointer to user space and point back to kernel space */
71 fs = get_fs(); 70 fs = get_fs();
72 set_fs(KERNEL_DS); 71 set_fs(KERNEL_DS);
73 72
73 mutex_lock(&sbi->pipe_mutex);
74 while (bytes && 74 while (bytes &&
75 (wr = file->f_op->write(file,data,bytes,&file->f_pos)) > 0) { 75 (wr = file->f_op->write(file,data,bytes,&file->f_pos)) > 0) {
76 data += wr; 76 data += wr;
77 bytes -= wr; 77 bytes -= wr;
78 } 78 }
79 mutex_lock(&sbi->pipe_mutex);
79 80
80 set_fs(fs); 81 set_fs(fs);
81 82
@@ -179,7 +180,7 @@ static void autofs4_notify_daemon(struct autofs_sb_info *sbi,
179 180
180 mutex_unlock(&sbi->wq_mutex); 181 mutex_unlock(&sbi->wq_mutex);
181 182
182 if (autofs4_write(pipe, &pkt, pktsz)) 183 if (autofs4_write(sbi, pipe, &pkt, pktsz))
183 autofs4_catatonic_mode(sbi); 184 autofs4_catatonic_mode(sbi);
184 fput(pipe); 185 fput(pipe);
185} 186}