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