ndmpd_callbacks.c revision 8a5de3ffa1408e996e1887c2131fefa579ec9571
/*
*/
/*
* BSD 3 Clause License
*
* Copyright (c) 2007, The Storage Networking Industry Association.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* distribution.
*
* - Neither the name of The Storage Networking Industry Association (SNIA)
* nor the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
/* Copyright (c) 2007, The Storage Networking Industry Association. */
/* Copyright (c) 1996, 1997 PDC, Network Appliance. All Rights Reserved */
#include <stdlib.h>
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include "ndmpd.h"
/*
* Message Id counter. This number is increased by MOD_LOGV3 macro.
* MOD_LOGCONTV3 macro uses the number generated by the last MOD_LOGV3.
*
*/
int ndmp_log_msg_id = 0;
/*
* ************************************************************************
* NDMP V2 CALLBACKS
* ************************************************************************
*/
/*
* ndmpd_api_done_v2
*
* Sends a notify_halt request to the NDMP client.
*
* Parameters:
* session (input) - session pointer.
* err (input) - UNIX error code.
*
* Returns:
* void
*/
void
{
return;
return;
/*
*/
/*
* If mover local and successfull backup, write any
* remaining buffered data to tape.
*/
err == 0) {
if (ndmpd_local_write(session, 0, 0) < 0)
}
}
switch (err) {
case 0:
break;
case EINTR:
break;
case EIO:
break;
default:
}
} else {
}
} else {
}
}
/*
* ndmpd_api_log_v2
*
* Sends a log request to the NDMP client.
*
* Parameters:
* cookie (input) - session pointer.
* str (input) - null terminated string
* format (input) - printf style format.
* ... (input) - format arguments.
*
* Returns:
* 0 - success.
* -1 - error.
*/
/*ARGSUSED*/
int
{
static char buf[1024];
return (-1);
/*LINTED variable format specifier */
NDMP_NO_ERR, (void *)&request, 0) < 0) {
return (-1);
}
return (0);
}
/*
* ndmpd_api_read_v2
*
* Reads data from the mover.
* If the mover is remote, the data is read from the data connection.
* If the mover is local, the data is read from the tape device.
*
* Parameters:
* client_data (input) - session pointer.
* data (input) - data to be written.
* length (input) - data length.
*
* Returns:
* 0 - data successfully read.
* -1 - error.
* 1 - session terminated or operation aborted.
*/
int
{
return (-1);
/*
* Read the data from the data connection if the mover is remote.
*/
else
}
/*
* ndmpd_api_seek_v2
*
* Seek to the specified position in the data stream and start a
* read for the specified amount of data.
*
* Parameters:
* cookie (input) - session pointer.
* offset (input) - stream position to seek to.
* length (input) - amount of data that will be read using ndmpd_api_read
*
* Returns:
* 0 - seek successful.
* -1 - error.
*/
int
{
int err;
return (-1);
/*
* Send a notify_data_read request if the mover is remote.
*/
(void *)&request, 0) < 0) {
"Sending notify_data_read request");
return (-1);
}
return (0);
}
/* Mover is local. */
if (err < 0) {
return (-1);
}
if (err == 0)
return (0);
/*
* NDMP client intervention is required to perform the seek.
* Wait for the client to either do the seek and send a continue
* request or send an abort request.
*/
for (; ; ) {
if (nlp_event_rv_get(session) < 0) {
return (-1);
}
return (-1);
}
case NDMP_MOVER_STATE_ACTIVE:
/*
* There is a bug in the original SDK code which
* causes to fall in an infinite loop after the
* break.
*/
break;
case NDMP_MOVER_STATE_PAUSED:
continue;
default:
return (-1);
}
}
}
/*
* ndmpd_api_file_recovered_v2
*
* Notify the NDMP client that the specified file was recovered.
*
* Parameters:
* cookie (input) - session pointer.
* name (input) - name of recovered file.
* error (input) - 0 if file successfully recovered.
* otherwise, error code indicating why recovery failed.
*
* Returns:
* void.
*/
int
{
return (-1);
switch (error) {
case 0:
break;
case ENOENT:
break;
default:
}
NDMP_NO_ERR, (void *)&request, 0) < 0) {
return (-1);
}
return (0);
}
/*
* ndmpd_api_write_v2
*
* Writes data to the mover.
* If the mover is remote, the data is written to the data connection.
* If the mover is local, the data is buffered and written to the
* tape device after a full record has been buffered.
*
* Parameters:
* client_data (input) - session pointer.
* data (input) - data to be written.
* length (input) - data length.
*
* Returns:
* 0 - data successfully written.
* -1 - error.
*/
int
{
return (-1);
/*
* Write the data to the data connection if the mover is remote.
*/
else
}
/*
* ************************************************************************
* NDMP V3 CALLBACKS
* ************************************************************************
*/
/*
* ndmpd_api_done_v3
*
* Called when the data module has completed.
* Sends a notify_halt request to the NDMP client.
*
* Parameters:
* session (input) - session pointer.
* err (input) - UNIX error code.
*
* Returns:
* void
*/
void
{
switch (err) {
case 0:
break;
case EINTR:
break;
case EIO:
break;
default:
}
}
/*
* ndmpd_api_log_v3
*
* Sends a log request to the NDMP client.
*
* Parameters:
* cookie (input) - session pointer.
* format (input) - printf style format.
* ... (input) - format arguments.
*
* Returns:
* 0 - success.
* -1 - error.
*/
/*ARGSUSED*/
int
char *format, ...)
{
static char buf[1024];
return (-1);
/*LINTED variable format specifier */
NDMP_NO_ERR, (void *)&request, 0) < 0) {
return (-1);
}
return (0);
}
/*
* ndmpd_api_write_v3
*
* Writes data to the mover.
* If the mover is remote, the data is written to the data connection.
* If the mover is local, the data is buffered and written to the
* tape device after a full record has been buffered.
*
* Parameters:
* client_data (input) - session pointer.
* data (input) - data to be written.
* length (input) - data length.
*
* Returns:
* 0 - data successfully written.
* -1 - error.
*/
int
{
return (-1);
/*
* Write the data to the tape if the mover is local, otherwise,
* write the data to the data connection.
*
* The same write function for of v2 can be used in V3
* for writing data to the data connection to the mover.
* So we don't need ndmpd_remote_write_v3().
*/
else
}
/*
* ndmpd_api_read_v3
*
* Reads data from the mover.
* If the mover is remote, the data is read from the data connection.
* If the mover is local, the data is read from the tape device.
*
* Parameters:
* client_data (input) - session pointer.
* data (input) - data to be written.
* length (input) - data length.
*
* Returns:
* 0 - data successfully read.
* -1 - error.
* 1 - session terminated or operation aborted.
*/
int
{
return (-1);
/*
* Read the data from the data connection if the mover is remote.
*/
else
}
/*
* ndmpd_api_get_name_v3
*
* Return the name entry at the specified index from the
* recover file name list.
*
* Parameters:
* cookie (input) - NDMP session pointer.
* name_index (input) - index of entry to be returned.
*
* Returns:
* Pointer to name entry.
* 0 if requested entry does not exist.
*/
void *
{
return (NULL);
return (NULL);
}
/*
* ndmpd_api_file_recovered_v3
*
* Notify the NDMP client that the specified file was recovered.
*
* Parameters:
* cookie (input) - session pointer.
* name (input) - name of recovered file.
* ssid (input) - selection set id.
* error (input) - 0 if file successfully recovered.
* otherwise, error code indicating why recovery failed.
*
* Returns:
* 0 - success.
* -1 - error.
*/
int
{
return (-1);
switch (error) {
case 0:
break;
case ENOENT:
break;
default:
}
NDMP_NO_ERR, (void *)&request, 0) < 0) {
return (-1);
}
return (0);
}
/*
* ndmpd_api_seek_v3
*
* Seek to the specified position in the data stream and start a
* read for the specified amount of data.
*
* Parameters:
* cookie (input) - session pointer.
* offset (input) - stream position to seek to.
* length (input) - amount of data that will be read using ndmpd_api_read
*
* Returns:
* 0 - seek successful.
* 1 - seek needed DMA(client) intervention.
* -1 - error.
*/
int
{
int err;
return (-1);
/*
* Send a notify_data_read request if the mover is remote.
*/
(void *)&request, 0) < 0) {
"Sending notify_data_read request");
return (-1);
}
return (0);
}
/* Mover is local. */
if (err < 0) {
return (-1);
}
if (err == 0)
return (0);
/*
* NDMP client intervention is required to perform the seek.
* Wait for the client to either do the seek and send a continue
* request or send an abort request.
*/
/*
* If we needed a client intervention, then we should be able to
* detect this in DAR.
*/
if (err == 0)
err = 1;
return (err);
}
/*
* ************************************************************************
* NDMP V4 CALLBACKS
* ************************************************************************
*/
/*
* ndmpd_api_log_v4
*
* Sends a log request to the NDMP client.
* No message association is supported now, but can be added later on
* in this function.
*
* Parameters:
* cookie (input) - session pointer.
* format (input) - printf style format.
* ... (input) - format arguments.
*
* Returns:
* 0 - success.
* -1 - error.
*/
/*ARGSUSED*/
int
char *format, ...)
{
static char buf[1024];
return (-1);
/*LINTED variable format specifier */
NDMP_NO_ERR, (void *)&request, 0) < 0) {
return (-1);
}
return (0);
}
/*
* ndmpd_api_file_recovered_v4
*
* Notify the NDMP client that the specified file was recovered.
*
* Parameters:
* cookie (input) - session pointer.
* name (input) - name of recovered file.
* ssid (input) - selection set id.
* error (input) - 0 if file successfully recovered.
* otherwise, error code indicating why recovery failed.
*
* Returns:
* void.
*/
int
{
return (-1);
switch (error) {
case 0:
break;
case EPERM:
break;
case ENOENT:
break;
case ENOTDIR:
break;
case ENOMEM:
break;
case EIO:
break;
case EEXIST:
break;
default:
break;
}
NDMP_NO_ERR, (void *)&request, 0) < 0) {
return (-1);
}
return (0);
}
/*
* ************************************************************************
* LOCALS
* ************************************************************************
*/
/*
* ndmpd_api_find_env
*
* Return the pointer of the environment variable from the variable
* array for the spcified environment variable.
*
* Parameters:
* cookie (input) - NDMP session pointer.
* name (input) - name of variable.
*
* Returns:
* Pointer to variable.
* NULL if variable not found.
*
*/
{
ulong_t i;
return (NULL);
return (envp);
return (NULL);
}
/*
* ndmpd_api_get_env
*
* Return the value of an environment variable from the variable array.
*
* Parameters:
* cookie (input) - NDMP session pointer.
* name (input) - name of variable.
*
* Returns:
* Pointer to variable value.
* 0 if variable not found.
*
*/
char *
{
if (envp)
return (NULL);
}
/*
* ndmpd_api_add_env
*
* variable list.
*
* Parameters:
* session (input) - session pointer.
* name (input) - variable name.
* val (input) - value.
*
* Returns:
* 0 - success.
* -1 - error.
*/
int
{
char *namebuf;
char *valbuf;
return (-1);
return (-1);
}
return (-1);
return (-1);
}
return (0);
}
/*
* ndmpd_api_set_env
*
* variable list. If the variable exists, it gets the new value,
* otherwise it's added as a new variable.
*
* Parameters:
* session (input) - session pointer.
* name (input) - variable name.
* val (input) - value.
*
* Returns:
* 0 - success.
* -1 - error.
*/
int
{
char *valbuf;
int rv;
if (!envp) {
rv = -1;
} else {
rv = 0;
}
return (rv);
}
/*
* ndmpd_api_get_name
*
* Return the name entry at the specified index from the
* recover file name list.
*
* Parameters:
* cookie (input) - NDMP session pointer.
* name_index (input) - index of entry to be returned.
*
* Returns:
* Pointer to name entry.
* 0 if requested entry does not exist.
*/
void *
{
return (NULL);
return (NULL);
}
/*
* ndmpd_api_dispatch
*
* Process pending NDMP client requests and check registered files for
* data availability.
*
* Parameters:
* cookie (input) - session pointer.
* block (input) -
* TRUE block until a request has been processed or
* until a file handler has been called.
* FALSE don't block.
*
* Returns:
* -1 - abort request received or connection closed.
* 0 - success.
*/
int
{
int err;
return (-1);
for (; ; ) {
return (-1);
if (err == 0)
return (0);
/*
* Something was processed.
* Set the block flag to false so that we will return as
* soon as everything available to be processed has been
* processed.
*/
}
}
/*
* ndmpd_api_add_file_handler
*
* Adds a file handler to the file handler list.
* The file handler list is used by ndmpd_api_dispatch.
*
* Parameters:
* daemon_cookie (input) - session pointer.
* cookie (input) - opaque data to be passed to file hander when called.
* fd (input) - file descriptor.
* mode (input) - bitmask of the following:
* NDMP_SELECT_MODE_READ = watch file for ready for reading
* NDMP_SELECT_MODE_WRITE = watch file for ready for writing
* NDMP_SELECT_MODE_EXCEPTION = watch file for exception
* func (input) - function to call when the file meets one of the
* conditions specified by mode.
*
* Returns:
* 0 - success.
* -1 - error.
*/
int
{
func));
}
/*
* ndmpd_api_remove_file_handler
*
* Removes a file handler from the file handler list.
*
* Parameters:
* cookie (input) - session pointer.
* fd (input) - file descriptor.
*
* Returns:
* 0 - success.
* -1 - error.
*/
int
{
}