[patch 10/18] monwriter: Serialization bug for multithreaded applications.



From: Melissa Howland <melissah@xxxxxxxxxx>

Locking added so that multithreaded applications can now do writes
from different threads without the risk of storage corruption.

Signed-off-by: Melissa Howland <melissah@xxxxxxxxxx>
Signed-off-by: Martin Schwidefsky <schwidefsky@xxxxxxxxxx>
---

drivers/s390/char/monwriter.c | 6 ++++++
1 file changed, 6 insertions(+)

Index: quilt-2.6/drivers/s390/char/monwriter.c
===================================================================
--- quilt-2.6.orig/drivers/s390/char/monwriter.c
+++ quilt-2.6/drivers/s390/char/monwriter.c
@@ -17,6 +17,7 @@
#include <linux/miscdevice.h>
#include <linux/ctype.h>
#include <linux/poll.h>
+#include <linux/mutex.h>
#include <asm/uaccess.h>
#include <asm/ebcdic.h>
#include <asm/io.h>
@@ -41,6 +42,7 @@ struct mon_private {
size_t hdr_to_read;
size_t data_to_read;
struct mon_buf *current_buf;
+ struct mutex thread_mutex;
};

/*
@@ -179,6 +181,7 @@ static int monwrite_open(struct inode *i
return -ENOMEM;
INIT_LIST_HEAD(&monpriv->list);
monpriv->hdr_to_read = sizeof(monpriv->hdr);
+ mutex_init(&monpriv->thread_mutex);
filp->private_data = monpriv;
return nonseekable_open(inode, filp);
}
@@ -209,6 +212,7 @@ static ssize_t monwrite_write(struct fil
void *to;
int rc;

+ mutex_lock(&monpriv->thread_mutex);
for (written = 0; written < count; ) {
if (monpriv->hdr_to_read) {
len = min(count - written, monpriv->hdr_to_read);
@@ -247,11 +251,13 @@ static ssize_t monwrite_write(struct fil
}
monpriv->hdr_to_read = sizeof(monpriv->hdr);
}
+ mutex_unlock(&monpriv->thread_mutex);
return written;

out_error:
monpriv->data_to_read = 0;
monpriv->hdr_to_read = sizeof(struct monwrite_hdr);
+ mutex_unlock(&monpriv->thread_mutex);
return rc;
}


--
blue skies,
Martin.

"Reality continues to ruin my life." - Calvin.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



Relevant Pages

  • Re: Cracking admin password on Win 2000; then putting it back?
    ... I would have thought that the act of locking down the pc by ... The bank would employ a standard build that has been tested with the ... >No its not bollocks by law each person must have a risk assesment ...
    (alt.computer.security)
  • Re: Boathouse etiquette
    ... (That also lessens the risk of someone locking up ... the boathouse while you're out, ...
    (rec.sport.rowing)
  • Re: Local policy per group
    ... >a local 2k or xp box, I know I can deny read access to the groups policy ... >folder, but the risk of locking myself out if great, maybe good old poledit, ...
    (microsoft.public.windows.group_policy)
  • Re: The Doors On The Latch (not really a repilos)
    ... I regard the risk of locking myself out (if Yale-type ... slam locks are used) greater than the risk of forgetting to lock ...
    (uk.media.radio.archers)