@@ -425,42 +425,15 @@ int line_setup_irq(int fd, int input, int output, struct line *line, void *data)
425425 * However, in this case, mconsole requests can come in "from the
426426 * side", and race with opens and closes.
427427 *
428- * The problem comes from line_setup not wanting to sleep if
429- * the device is open or being opened. This can happen because the
430- * first opener of a device is responsible for setting it up on the
431- * host, and that can sleep . The open of a port device will sleep
432- * until someone telnets to it .
428+ * mconsole config requests will want to be sure the device isn't in
429+ * use, and get_config, open, and close will want a stable
430+ * configuration. The checking and modification of the configuration
431+ * is done under a spinlock . Checking whether the device is in use is
432+ * line->tty->count > 1, also under the spinlock .
433433 *
434- * The obvious solution of putting everything under a mutex fails
435- * because then trying (and failing) to change the configuration of an
436- * open(ing) device will block until the open finishes. The right
437- * thing to happen is for it to fail immediately.
438- *
439- * We can put the opening (and closing) of the host device under a
440- * separate lock, but that has to be taken before the count lock is
441- * released. Otherwise, you open a window in which another open can
442- * come through and assume that the host side is opened and working.
443- *
444- * So, if the tty count is one, open will take the open mutex
445- * inside the count lock. Otherwise, it just returns. This will sleep
446- * if the last close is pending, and will block a setup or get_config,
447- * but that should not last long.
448- *
449- * So, what we end up with is that open and close take the count lock.
450- * If the first open or last close are happening, then the open mutex
451- * is taken inside the count lock and the host opening or closing is done.
452- *
453- * setup and get_config only take the count lock. setup modifies the
454- * device configuration only if the open count is zero. Arbitrarily
455- * long blocking of setup doesn't happen because something would have to be
456- * waiting for an open to happen. However, a second open with
457- * tty->count == 1 can't happen, and a close can't happen until the open
458- * had finished.
459- *
460- * We can't maintain our own count here because the tty layer doesn't
461- * match opens and closes. It will call close if an open failed, and
462- * a tty hangup will result in excess closes. So, we rely on
463- * tty->count instead. It is one on both the first open and last close.
434+ * tty->count serves to decide whether the device should be enabled or
435+ * disabled on the host. If it's equal to 1, then we are doing the
436+ * first open or last close. Otherwise, open and close just return.
464437 */
465438
466439int line_open (struct line * lines , struct tty_struct * tty )
@@ -476,7 +449,6 @@ int line_open(struct line *lines, struct tty_struct *tty)
476449 if (tty -> count > 1 )
477450 goto out_unlock ;
478451
479- mutex_lock (& line -> open_mutex );
480452 spin_unlock (& line -> count_lock );
481453
482454 tty -> driver_data = line ;
@@ -493,7 +465,6 @@ int line_open(struct line *lines, struct tty_struct *tty)
493465 chan_window_size (& line -> chan_list , & tty -> winsize .ws_row ,
494466 & tty -> winsize .ws_col );
495467
496- mutex_unlock (& line -> open_mutex );
497468 return err ;
498469
499470out_unlock :
@@ -523,7 +494,6 @@ void line_close(struct tty_struct *tty, struct file * filp)
523494 if (tty -> count > 1 )
524495 goto out_unlock ;
525496
526- mutex_lock (& line -> open_mutex );
527497 spin_unlock (& line -> count_lock );
528498
529499 line -> tty = NULL ;
@@ -534,7 +504,6 @@ void line_close(struct tty_struct *tty, struct file * filp)
534504 line -> sigio = 0 ;
535505 }
536506
537- mutex_unlock (& line -> open_mutex );
538507 return ;
539508
540509out_unlock :
@@ -755,7 +724,6 @@ void lines_init(struct line *lines, int nlines, struct chan_opts *opts)
755724 for (i = 0 ; i < nlines ; i ++ ){
756725 line = & lines [i ];
757726 INIT_LIST_HEAD (& line -> chan_list );
758- mutex_init (& line -> open_mutex );
759727
760728 if (line -> init_str == NULL )
761729 continue ;
0 commit comments