1N/A * The contents of this file are subject to the terms of the 1N/A * Common Development and Distribution License (the "License"). 1N/A * You may not use this file except in compliance with the License. 1N/A * See the License for the specific language governing permissions 1N/A * and limitations under the License. 1N/A * When distributing Covered Code, include this CDDL HEADER in each 1N/A * If applicable, add the following below this CDDL HEADER, with the 1N/A * fields enclosed by brackets "[]" replaced with your own identifying 1N/A * information: Portions Copyright [yyyy] [name of copyright owner] 1N/A * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 1N/A * Use is subject to license terms. 1N/A * vntsd uses configuration information provided by vcc to export access 1N/A * to Ldom console access over regular TCP sockets. When it starts, it opens 1N/A * the vcc driver control port and obtains the list of ports that have been 1N/A * created by the vcc driver as well as TCP port number and group associated 1N/A * vntsd consists of multiple components as the follows: 1N/A * This module initializes vnts daemon, process user options such as instance 1N/A * number, ip address and etc., and provides main thread to poll any console 1N/A * This module provides vcc driver interface. It opens vcc driver control 1N/A * ports, read initial configuration, and provides interface to read, write and 1N/A * ioctl virtual console ports. This module creates a listen thread for each 1N/A * console group. It further dynamically adds and removes virtual consoles 1N/A * and groups following instructions of the vcc driver. This module 1N/A * is executed in the same thread as vntsd.c which is blocked on vcc control 1N/A * This is a group listen thread. Each group's tcp-port has a listen thread 1N/A * associated with it. The thread is created when a console is associated with 1N/A * a new group and is removed when all consoles in the group are removed. 1N/A * This is a console selection thread. The thread is created when a client 1N/A * connects to a group TCP port and exited when client disconnects. If there is 1N/A * only one console in the group, the client is connected to that console. If 1N/A * there are multiple consoles in the group, the client is asked to select a 1N/A * console. After determining which console to connect to, this thread 1N/A * a write thread if the cient is a writer and it self read in client input. 1N/A * it reads input from a TCP client, processes 1N/A * special daemon and telent commands and write to vcc driver if the client 1N/A * is a writer. The client is a writer if the client is the first one connects 1N/A * to the console. Read thread print out an error message if a reader attempt 1N/A * to input to vcc. Read thread exits if console is deleted, client 1N/A * disconnects, or there is a fatal error. 1N/A * Write thread is creaed when first client connects to a console. It reads 1N/A * from vcc and writes to all clients that connect to the same console. 1N/A * Write thread exits when all clients disconnect from the console. 1N/A * This is a supporting module for handling special daemon and telnet commands. 1N/A * supporting modules shared by threads modules. 1N/A * This is a moudle supporting queue operations. Vntsd organizes its data 1N/A * in multiple queues <see data structure below>. 1N/A * This is a manifest to support SMF interfaces. 1N/A * each group has a vntsd_group_t structure, which contains a queue of 1N/A * all console in that group. 1N/A * each console has a vntsd_cons_t structure, which contains a queue of 1N/A * all clients that connected to the console. 1N/A * +----------+ +----------+ +----------+ 1N/A * | group |-->| group |-->| group |-->.... 1N/A * +----------+ +----------+ +----------+ 1N/A * |<-----------------------------------------+ 1N/A * |<------------------------+ | 1N/A * | +----------+ +----------+ +----------+ 1N/A * +----->| console |---->| console |---->| lconsole |---> .... 1N/A * +----------+ +----------+ +----------+ 1N/A * | | +----------+ +----------+ 1N/A * | +---->| client |----->| client |----->...... 1N/A * | +----------+ +----------+ 1N/A * |<------------------------------+ 1N/A * Each vntsd has one lock to protect the group queue 1N/A * Each group has one lock to protect the console queue, the queue for 1N/A * clients without a console connection and status. 1N/A * Each console has one lock to protect client queue and status. 1N/A * Each client has one lock to protect the state of the client. The client 1N/A * A client is connected to a console as either a writer or a reader. 1N/A * if this client is the first one connects the console, the client is 1N/A * a writer, otherwise the client is a reader. A writer' write thread 1N/A * reads from vcc and send output to all readers connected to the 1N/A * same console. a reader's write thread is blocked until a reader becomes 1N/A * When a client selected a console, the client becomes a reader if 1N/A * there is another client connected to the console before the client. 1N/A * A client will be a writer if 1N/A * 1. client is the first one connected to the console or 1N/A * 2. client has entered a ~w daemon command or 1N/A * 3. all clients connected to the console before the client have 1N/A * disconnected from the console. 1N/A * VCC_CLIENT_MOVE_CONS_FORWARD 1N/A * VCC_CLIENT_MOVE_CONS_BACKWOARD 1N/A * A client is disconnecting from one console and move to the next or 1N/A * previous console in the group queue. 1N/A * A client is in one of these state if 1N/A * 1. the client has entered the daemon command and 1N/A * 2. the vntsd is in process of switching the client from one 1N/A * console to another. 1N/A * VCC_CLIENT_DISABLE_DAEMON_CMD 1N/A * vntsd is in processing of a client's daemon command or the client is 1N/A * in selecting console. 1N/A * A client is in this state if 1N/A * 1. the client has not selected a console or 1N/A * 2. the vntsd is processing a client's daemon command. 1N/A * VCC_CLIENT_ACQUIRE_WRITER 1N/A * A reader forces to become a writer via vntsd special command. 1N/A * A client is in this state if 1N/A * 1. the client is a reader and 1N/A * 2. client has entered a daemon command to become a writer. 1N/A * VCC_CLIENT_CONS_DELETED 1N/A * The console that the client is connected to is being deleted and 1N/A * waiting for the client to disconnect. 1N/A * A client is in this state if 1N/A * 1. the console a client is connected to is being removed and 1N/A * 2. the vntsd is in process of disconnecting the client from the console. 1N/A/* secons before re-send signal for cv_wait */ 1N/A/* common messages */ 1N/A * When a console is removed or vntsd is exiting, main thread 1N/A * notifies listen, read and write thread to exit. 1N/A * After those threads exit, main thread clears up group structurre. 1N/A * VNTSD_GROUP_SIG_WAIT 1N/A * The main thread is waiting for listen thread to exit. 1N/A * VNTSD_GROUP_CLEAN_CONS 1N/A * There are console(s) in the group that are being removed. 1N/A * This is a transition state where the corresponding vcc port has been 1N/A * removed, but vntsd has not done its clean up yet. 1N/A * VNTSD_GROUP_IN_CLEANUP 1N/A * vntsd main thread has started cleaning up the group. 1N/A * There are two states when a console is removed 1N/A * VNTSD_CONS_DELETED 1N/A * the console is being deleted 1N/A * VNTSD_CONS_SIG_WAIT 1N/A * console is waiting for all clients to exit. 1N/A/* generic que structure */ 1N/A/* client structure */ char prev_char;
/* previous char read by this client */ int vcc_fd;
/* vcc console port */ int sockfd;
/* listen socket */ /* clients have no console connection */ int timeout;
/* connection timeout */ /* handle for creating thread */ /* vntsd status and error definitions */ /* create thread errors */ /* listen thread errors */ /* tcp client read and write errors */ /* function prototype defines */