Print this page
NEX-13374 NDMP should be able to backup unmounted ZFS filesystems
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
NEX-9532 NDMP: readdir errors when file/directory has special characters
Reviewed by: Peer Dampmann <peer.dampmann@nexenta.com>
Reviewed by: Alexander Eremin <alexander.eremin@nexenta.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
NEX-5801 Snapshots left over after failed backups
Reviewed by: Rick Mesta <rick.mesta@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Revert "NEX-5801 Snapshots left over after failed backups"
This reverts commit f182fb95f09036db71fbfc6f0a6b90469b761f21.
NEX-5801 Snapshots left over after failed backups
Reviewed by: Rick Mesta <rick.mesta@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
NEX-2990 ndmpd dumping core when used with ndmpcopy
NEX-2911 NDMP logging should use syslog and is too chatty
NEX-559 NDMP cannot backup/restore a file which spans multiple tapes
@@ -1,7 +1,8 @@
/*
* Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
*/
/*
* BSD 3 Clause License
*
@@ -35,15 +36,16 @@
* 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 */
-/* Copyright 2014 Nexenta Systems, Inc. All rights reserved. */
+/* Copyright 2017 Nexenta Systems, Inc. All rights reserved. */
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/socket.h>
+#include <syslog.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
@@ -82,16 +84,14 @@
long xfer_size;
ndmp_lbr_params_t *nlp;
tlm_commands_t *cmds;
if ((nlp = ndmp_get_nlp(session)) == NULL) {
- NDMP_LOG(LOG_DEBUG, "nlp == NULL");
return (-1);
}
if ((nlp->nlp_jstat = tlm_new_job_stats(jname)) == NULL) {
- NDMP_LOG(LOG_DEBUG, "Creating job stats");
return (-1);
}
cmds = &nlp->nlp_cmds;
(void) memset(cmds, 0, sizeof (*cmds));
@@ -104,16 +104,16 @@
* when we write the data.
*/
if ((n = (512 * KILOBYTE/xfer_size)) <= 0)
n = 1;
xfer_size *= n;
- NDMP_LOG(LOG_DEBUG, "Adjusted read size: %d", xfer_size);
+ syslog(LOG_DEBUG, "Adjusted read size: %d", xfer_size);
}
cmds->tcs_command = tlm_create_reader_writer_ipc(TRUE, xfer_size);
if (cmds->tcs_command == NULL) {
- NDMP_LOG(LOG_DEBUG, "Error creating ipc buffers");
+ syslog(LOG_ERR, "Error creating ipc buffers");
tlm_un_ref_job_stats(jname);
return (-1);
}
nlp->nlp_logcallbacks = lbrlog_callbacks_init(session,
@@ -151,25 +151,23 @@
long xfer_size;
ndmp_lbr_params_t *nlp;
tlm_commands_t *cmds;
if ((nlp = ndmp_get_nlp(session)) == NULL) {
- NDMP_LOG(LOG_DEBUG, "nlp == NULL");
return (-1);
}
if ((nlp->nlp_jstat = tlm_new_job_stats(jname)) == NULL) {
- NDMP_LOG(LOG_DEBUG, "Creating job stats");
return (-1);
}
cmds = &nlp->nlp_cmds;
(void) memset(cmds, 0, sizeof (*cmds));
xfer_size = ndmp_buffer_get_size(session);
cmds->tcs_command = tlm_create_reader_writer_ipc(FALSE, xfer_size);
if (cmds->tcs_command == NULL) {
- NDMP_LOG(LOG_DEBUG, "Error creating ipc buffers");
+ syslog(LOG_ERR, "Error creating ipc buffers");
tlm_un_ref_job_stats(jname);
return (-1);
}
nlp->nlp_logcallbacks = lbrlog_callbacks_init(session,
@@ -213,37 +211,33 @@
{
int i, rv;
ndmp_name *ent;
if (params == NULL) {
- NDMP_LOG(LOG_DEBUG, "params == NULL");
return (-1);
}
if (nlp == NULL) {
- NDMP_LOG(LOG_DEBUG, "nlp == NULL");
return (-1);
}
rv = 0;
for (i = 0; i < (int)nlp->nlp_nfiles; i++) {
- NDMP_LOG(LOG_DEBUG, "nlp->nlp_restored[%d]: %s", i,
+ syslog(LOG_DEBUG, "nlp->nlp_restored[%d]: %s", i,
nlp->nlp_restored[i] ? "TRUE" : "FALSE");
if (!nlp->nlp_restored[i]) {
ent = (ndmp_name *)MOD_GETNAME(params, i);
if (ent == NULL) {
- NDMP_LOG(LOG_DEBUG, "ent == NULL");
rv = -1;
break;
}
if (ent->name == NULL) {
- NDMP_LOG(LOG_DEBUG, "ent->name == NULL");
rv = -1;
break;
}
- NDMP_LOG(LOG_DEBUG, "ent.name: \"%s\"", ent->name);
+ syslog(LOG_DEBUG, "ent.name: \"%s\"", ent->name);
rv = MOD_FILERECOVERD(params, ent->name, ENOENT);
if (rv < 0)
break;
}
@@ -270,34 +264,26 @@
{
ndmp_lbr_params_t *nlp;
tlm_commands_t *cmds;
if ((nlp = ndmp_get_nlp(session)) == NULL) {
- NDMP_LOG(LOG_DEBUG, "nlp == NULL");
return;
}
cmds = &nlp->nlp_cmds;
if (cmds == NULL) {
- NDMP_LOG(LOG_DEBUG, "cmds == NULL");
return;
}
if (nlp->nlp_logcallbacks != NULL) {
lbrlog_callbacks_done(nlp->nlp_logcallbacks);
nlp->nlp_logcallbacks = NULL;
- } else {
- NDMP_LOG(LOG_DEBUG, "FH CALLBACKS == NULL");
}
if (cmds->tcs_command != NULL) {
if (cmds->tcs_command->tc_buffers != NULL)
tlm_release_reader_writer_ipc(cmds->tcs_command);
- else
- NDMP_LOG(LOG_DEBUG, "BUFFERS == NULL");
cmds->tcs_command = NULL;
- } else {
- NDMP_LOG(LOG_DEBUG, "COMMAND == NULL");
}
if (nlp->nlp_bkmap >= 0) {
(void) dbm_free(nlp->nlp_bkmap);
nlp->nlp_bkmap = -1;
@@ -305,12 +291,10 @@
if (session->ns_data.dd_operation == NDMP_DATA_OP_RECOVER &&
nlp->nlp_restored != NULL) {
free(nlp->nlp_restored);
nlp->nlp_restored = NULL;
- } else {
- NDMP_LOG(LOG_DEBUG, "nlp_restored == NULL");
}
}
/*
* ndmp_write_utf8magic
@@ -323,18 +307,16 @@
{
char *cp;
long actual_size;
if (cmd->tc_buffers == NULL) {
- NDMP_LOG(LOG_DEBUG, "cmd->tc_buffers == NULL");
return (-1);
}
cp = tlm_get_write_buffer(RECORDSIZE, &actual_size,
cmd->tc_buffers, TRUE);
if (actual_size < RECORDSIZE) {
- NDMP_LOG(LOG_DEBUG, "Couldn't get enough buffer");
return (-1);
}
(void) strlcpy(cp, NDMPUTF8MAGIC, RECORDSIZE);
return (0);
@@ -375,12 +357,10 @@
{
ndmp_lbr_params_t *nlp;
nlp = (ndmp_lbr_params_t *)bksp->bs_cookie;
if (S_ISDIR(attr->st_mode) && ndmp_force_bk_dirs) {
- NDMP_LOG(LOG_DEBUG, "d(%lu)",
- (uint_t)attr->st_ino);
return (TRUE);
}
if (S_ISDIR(attr->st_mode) &&
dbm_getone(nlp->nlp_bkmap, (u_longlong_t)attr->st_ino) &&
((NLP_ISDUMP(nlp) && ndmp_dump_path_node) ||
@@ -398,32 +378,32 @@
* requirement. This requirement makes sense for dump format
* but for 'tar' format, it does not. In provision to the
* NDMP-v4 spec, for 'tar' format the intermediate directories
* need not to be reported.
*/
- NDMP_LOG(LOG_DEBUG, "p(%lu)", (u_longlong_t)attr->st_ino);
+ syslog(LOG_DEBUG, "p(%lu)", (u_longlong_t)attr->st_ino);
return (TRUE);
}
if (attr->st_mtime > bksp->bs_ldate) {
- NDMP_LOG(LOG_DEBUG, "m(%lu): %lu > %lu",
+ syslog(LOG_DEBUG, "m(%lu): %lu > %lu",
(uint_t)attr->st_ino, (uint_t)attr->st_mtime,
(uint_t)bksp->bs_ldate);
return (TRUE);
}
if (attr->st_ctime > bksp->bs_ldate) {
if (NLP_IGNCTIME(nlp)) {
- NDMP_LOG(LOG_DEBUG, "ign c(%lu): %lu > %lu",
+ syslog(LOG_DEBUG, "ign c(%lu): %lu > %lu",
(uint_t)attr->st_ino, (uint_t)attr->st_ctime,
(uint_t)bksp->bs_ldate);
return (FALSE);
}
- NDMP_LOG(LOG_DEBUG, "c(%lu): %lu > %lu",
+ syslog(LOG_DEBUG, "c(%lu): %lu > %lu",
(uint_t)attr->st_ino, (uint_t)attr->st_ctime,
(uint_t)bksp->bs_ldate);
return (TRUE);
}
- NDMP_LOG(LOG_DEBUG, "mc(%lu): (%lu,%lu) < %lu",
+ syslog(LOG_DEBUG, "mc(%lu): (%lu,%lu) < %lu",
(uint_t)attr->st_ino, (uint_t)attr->st_mtime,
(uint_t)attr->st_ctime, (uint_t)bksp->bs_ldate);
return (FALSE);
}
@@ -440,17 +420,17 @@
acl_t *aclp = NULL;
char *acltp;
erc = lstat64(name, &tlm_acls->acl_attr);
if (erc != 0) {
- NDMP_LOG(LOG_ERR, "Could not find file %s.", name);
+ syslog(LOG_ERR, "Could not find file %s.", name);
erc = TLM_NO_SOURCE_FILE;
return (erc);
}
erc = acl_get(name, ACL_NO_TRIVIAL, &aclp);
if (erc != 0) {
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_DEBUG,
"Could not read ACL for file [%s]", name);
erc = TLM_NO_SOURCE_FILE;
return (erc);
}
if (aclp && (acltp = acl_totext(aclp,
@@ -487,11 +467,11 @@
js->js_job_name);
else
fil = dir;
erc = lstat64(fil, &tlm_acls->acl_attr);
if (erc != 0) {
- NDMP_LOG(LOG_ERR, "Could not find directory %s.", dir);
+ syslog(LOG_ERR, "Could not find directory %s.", dir);
free(checkpointed_dir);
return (-1);
}
spot = strchr(&fil[1], '/');
@@ -505,21 +485,21 @@
if (strcmp(root_dir, tlm_acls->acl_root_dir) != 0) {
struct stat64 attr;
erc = lstat64(root_dir, &attr);
if (erc != 0) {
- NDMP_LOG(LOG_ERR, "Cannot find root directory %s.",
+ syslog(LOG_ERR, "Cannot find root directory %s.",
root_dir);
free(checkpointed_dir);
return (-1);
}
(void) strlcpy(tlm_acls->acl_root_dir, root_dir,
TLM_VOLNAME_MAX_LENGTH);
}
erc = acl_get(fil, ACL_NO_TRIVIAL, &aclp);
if (erc != 0) {
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_DEBUG,
"Could not read metadata for directory [%s]", dir);
free(checkpointed_dir);
return (-1);
}
if (aclp && (acltp = acl_totext(aclp,
@@ -544,23 +524,21 @@
tlm_cmd_t *local_commands, tlm_job_stats_t *job_stats,
bk_selector_t *bksp)
{
int erc;
- NDMP_LOG(LOG_DEBUG, "\"%s\"", dir);
-
erc = get_dir_acl_info(dir, tlm_acls, job_stats);
if (erc != 0) {
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_ERR,
"Could not read directory info for %s", dir);
job_stats->js_errors++;
} else {
/*
* See if the directory must be backed up.
*/
if (bksp && !(*bksp->bs_fn)(bksp, &tlm_acls->acl_attr)) {
- NDMP_LOG(LOG_DEBUG, "[%s] dir skipped", dir);
+ syslog(LOG_DEBUG, "[%s] dir skipped", dir);
return (erc);
}
if (tm_tar_ops.tm_putdir != NULL)
(void) (tm_tar_ops.tm_putdir)(dir, tlm_acls,
@@ -582,14 +560,12 @@
tlm_job_stats_t *job_stats, bk_selector_t *bksp)
{
int erc;
char buf[TLM_MAX_PATH_NAME];
- longlong_t rv;
+ longlong_t rv = -1;
- NDMP_LOG(LOG_DEBUG, "\"%s/%s\"", dir, name);
-
(void) strlcpy(buf, dir, sizeof (buf));
(void) strlcat(buf, "/", sizeof (buf));
(void) strlcat(buf, name, sizeof (buf));
/*
@@ -597,28 +573,28 @@
* This is not efficient when the attributes and file handle of
* the file is already known.
*/
erc = get_acl_info(buf, tlm_acls);
if (erc != TLM_NO_ERRORS) {
- NDMP_LOG(LOG_ERR, "Could not open file %s/%s.", dir, name);
+ syslog(LOG_ERR, "Could not open file %s/%s.", dir, name);
return (-ENOENT);
}
/* Should the file be backed up? */
if (!bksp) {
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_DEBUG,
"[%s/%s] has no selection criteria", dir, name);
} else if (!((*bksp->bs_fn)(bksp, &tlm_acls->acl_attr))) {
- NDMP_LOG(LOG_DEBUG, "[%s/%s] file skipped", dir, name);
+ syslog(LOG_DEBUG, "[%s/%s] file skipped", dir, name);
return (0);
}
/* Only the regular files and symbolic links can be backed up. */
if (!S_ISLNK(tlm_acls->acl_attr.st_mode) &&
!S_ISREG(tlm_acls->acl_attr.st_mode)) {
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_DEBUG,
"Warning: skip backing up [%s][%s]", dir, name);
return (-EINVAL);
}
@@ -656,11 +632,11 @@
longlong_t fsize;
bk_selector_t bks;
tlm_cmd_t *local_commands;
long dpos;
- NDMP_LOG(LOG_DEBUG, "nr_chkpnted %d nr_ldate: %u bk_path: \"%s\"",
+ syslog(LOG_DEBUG, "nr_chkpnted %d nr_ldate: %u bk_path: \"%s\"",
NLP_ISCHKPNTED(nlp), nlp->nlp_ldate, bk_path);
/* Get every name in this directory */
dname = ndmp_malloc(TLM_MAX_PATH_NAME);
if (dname == NULL)
@@ -676,11 +652,11 @@
/*
* should we skip the whole thing?
*/
if (tlm_is_excluded("", bk_path, np->nr_excls)) {
- NDMP_LOG(LOG_DEBUG, "%s excluded", bk_path);
+ syslog(LOG_DEBUG, "%s excluded", bk_path);
free(dname);
return (0);
}
/*
@@ -695,18 +671,18 @@
}
(void) memset(&ret_fh, 0, sizeof (ret_fh));
erc = fs_getstat(first_name, &ret_fh, &ret_attr);
if (erc != 0) {
- NDMP_LOG(LOG_ERR, "Path %s not found.", first_name);
+ syslog(LOG_ERR, "Path %s not found.", first_name);
free(dname);
return (-EINVAL);
}
if ((stk = cstack_new()) == NULL) {
free(dname);
- NDMP_LOG(LOG_DEBUG, "cstack_new failed");
+ syslog(LOG_DEBUG, "cstack_new failed");
return (-ENOMEM);
}
(void) strlcpy(dir_info.fd_dir_name, first_name, TLM_MAX_PATH_NAME);
(void) memcpy(&dir_info.fd_dir_fh, &ret_fh, sizeof (fs_fhandle_t));
p_dir_info = dup_dir_info(&dir_info);
@@ -717,11 +693,11 @@
*/
if (cstack_push(stk, p_dir_info, 0)) {
free(dname);
free(p_dir_info);
cstack_delete(stk);
- NDMP_LOG(LOG_DEBUG, "cstack_push failed");
+ syslog(LOG_DEBUG, "cstack_push failed");
return (-ENOMEM);
}
(void) memset(&tlm_acls, 0, sizeof (tlm_acls));
/*
@@ -737,11 +713,11 @@
/*
* This is level-backup. It never resets the archive bit.
*/
tlm_acls.acl_clear_archive = FALSE;
- NDMP_LOG(LOG_DEBUG, "acls.chkpnt: %c acls.clear_arcbit: %c",
+ syslog(LOG_DEBUG, "acls.chkpnt: %c acls.clear_arcbit: %c",
NDMP_YORN(tlm_acls.acl_checkpointed),
NDMP_YORN(tlm_acls.acl_clear_archive));
while (commands->tcs_reader == TLM_BACKUP_RUN &&
local_commands->tc_reader == TLM_BACKUP_RUN &&
@@ -761,21 +737,21 @@
while (commands->tcs_reader == TLM_BACKUP_RUN &&
local_commands->tc_reader == TLM_BACKUP_RUN) {
dname_size = TLM_MAX_PATH_NAME - 1;
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_DEBUG,
"dir_name: %s", p_dir_info->fd_dir_name);
(void) memset(&ret_fh, 0, sizeof (ret_fh));
erc = fs_readdir(&p_dir_info->fd_dir_fh,
p_dir_info->fd_dir_name, &dpos,
dname, &dname_size, &ret_fh, &ret_attr);
if (erc == 0) {
fileid = ret_fh.fh_fid;
} else {
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_DEBUG,
"Filesystem readdir in [%s]",
p_dir_info->fd_dir_name);
retval = -ENOENT;
break;
}
@@ -783,12 +759,10 @@
/* an empty name size marks the end of the list */
if (dname_size == 0)
break;
dname[dname_size] = '\0';
- NDMP_LOG(LOG_DEBUG, "dname: \"%s\"", dname);
-
/*
* If name refers to a directory, push its file
* handle onto the stack (skip "." and "..").
*/
if (rootfs_dot_or_dotdot(dname)) {
@@ -802,11 +776,11 @@
* Or
* dir-type entries which have have nothing under
* their hierarchy to be backed up.
*/
if (!dbm_getone(nlp->nlp_bkmap, (u_longlong_t)fileid)) {
- NDMP_LOG(LOG_DEBUG, "Skipping %s/%s",
+ syslog(LOG_DEBUG, "Skipping %s/%s",
p_dir_info->fd_dir_name, dname);
fileid = 0;
continue;
}
@@ -821,16 +795,16 @@
* so we do not have to test for regular files.
*/
t_dir_info = tlm_new_dir_info(&ret_fh,
p_dir_info->fd_dir_name, dname);
if (t_dir_info == NULL) {
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_DEBUG,
"While backing up [%s][%s]",
p_dir_info->fd_dir_name, dname);
} else if (cstack_push(stk, t_dir_info,
0) != 0) {
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_DEBUG,
"No enough memory stack_push");
retval = -ENOMEM;
break;
}
} else if (S_ISREG(ret_attr.st_mode) ||
@@ -916,11 +890,11 @@
int retval;
ndmp_run_args_t np;
tlm_job_stats_t *job_stats;
tlm_cmd_t *local_commands;
- NDMP_LOG(LOG_DEBUG, "bk_path: \"%s\"", nlp->nlp_backup_path);
+ syslog(LOG_DEBUG, "bk_path: \"%s\"", nlp->nlp_backup_path);
local_commands = commands->tcs_command;
(void) memset(&np, 0, sizeof (np));
if (!malloc_paths(&np))
return (-1);
@@ -960,17 +934,14 @@
tlm_buffers_t *bufs;
tlm_cmd_t *lcmd; /* Local command */
err = 0;
if (session == NULL) {
- NDMP_LOG(LOG_DEBUG, "session == NULL");
err = -1;
} else if (mod_params == NULL) {
- NDMP_LOG(LOG_DEBUG, "mod_params == NULL");
err = -1;
} else if (cmds == NULL) {
- NDMP_LOG(LOG_DEBUG, "cmds == NULL");
err = -1;
}
if (err != 0)
return (err);
@@ -984,15 +955,13 @@
nw = 0;
buf = tlm_buffer_out_buf(bufs, &bidx);
while (cmds->tcs_writer != (int)TLM_ABORT &&
lcmd->tc_writer != (int)TLM_ABORT) {
if (buf->tb_full) {
- NDMP_LOG(LOG_DEBUG, "w%d", bidx);
-
if (MOD_WRITE(mod_params, buf->tb_buffer_data,
buf->tb_buffer_size) != 0) {
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_DEBUG,
"Writing buffer %d, pos: %lld",
bidx, session->ns_mover.md_position);
err = -1;
break;
}
@@ -1003,32 +972,17 @@
tlm_buffer_release_out_buf(bufs);
nw++;
} else {
if (lcmd->tc_writer != TLM_BACKUP_RUN) {
/* No more data is comming; time to exit. */
- NDMP_LOG(LOG_DEBUG,
- "tc_writer!=TLM_BACKUP_RUN; time to exit");
break;
} else {
- NDMP_LOG(LOG_DEBUG, "W%d", bidx);
tlm_buffer_in_buf_timed_wait(bufs, 100);
}
}
}
- NDMP_LOG(LOG_DEBUG, "nw: %d", nw);
- if (cmds->tcs_writer != (int)TLM_ABORT) {
- NDMP_LOG(LOG_DEBUG, "tcs_writer != TLM_ABORT");
- } else {
- NDMP_LOG(LOG_DEBUG, "tcs_writer == TLM_ABORT");
- }
-
- if (lcmd->tc_writer != (int)TLM_ABORT) {
- NDMP_LOG(LOG_DEBUG, "tc_writer != TLM_ABORT");
- } else {
- NDMP_LOG(LOG_DEBUG, "tc_writer == TLM_ABORT");
- }
cmds->tcs_writer_count--;
lcmd->tc_reader = TLM_STOP;
lcmd->tc_ref--;
return (err);
@@ -1086,14 +1040,12 @@
mod_params = argp->tr_mod_params;
cmds = argp->tr_cmds;
err = 0;
if (session == NULL) {
- NDMP_LOG(LOG_DEBUG, "session == NULL");
err = -1;
} else if (cmds == NULL) {
- NDMP_LOG(LOG_DEBUG, "cmds == NULL");
err = -1;
}
if (err != 0) {
tlm_cmd_signal(cmds->tcs_command, TLM_TAR_READER);
@@ -1114,31 +1066,28 @@
buf = tlm_buffer_in_buf(bufs, &bidx);
while (cmds->tcs_reader == TLM_RESTORE_RUN &&
lcmd->tc_reader == TLM_RESTORE_RUN) {
if (buf->tb_full) {
- NDMP_LOG(LOG_DEBUG, "R%d", bidx);
/*
* The buffer is still full, wait for the consumer
* thread to use it.
*/
tlm_buffer_out_buf_timed_wait(bufs, 100);
buf = tlm_buffer_in_buf(bufs, NULL);
} else {
- NDMP_LOG(LOG_DEBUG, "r%d", bidx);
-
err = read_one_buf(mod_params, bufs, buf);
if (err < 0) {
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_DEBUG,
"Reading buffer %d, pos: %lld",
bidx, session->ns_mover.md_position);
/* Force the writer to stop. */
buf->tb_eot = buf->tb_eof = TRUE;
break;
} else if (err == 1) {
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_DEBUG,
"operation aborted or session terminated");
err = 0;
break;
}
@@ -1177,11 +1126,11 @@
char jname[TLM_MAX_BACKUP_JOB_NAME];
int err;
tlm_commands_t *cmds;
if (mod_params->mp_operation != NDMP_DATA_OP_BACKUP) {
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_DEBUG,
"mod_params->mp_operation != NDMP_DATA_OP_BACKUP");
err = -1;
} else {
if (ndmpd_mark_inodes_v2(session, nlp) != 0)
err = -1;
@@ -1192,14 +1141,16 @@
}
if (err != 0)
return (err);
- (void) ndmp_new_job_name(jname);
- if (backup_create_structs(session, jname) < 0)
+ if (ndmp_new_job_name(jname, sizeof (jname)) <= 0) {
return (-1);
-
+ }
+ if (backup_create_structs(session, jname) < 0) {
+ return (-1);
+ }
nlp->nlp_jstat->js_start_ltime = time(NULL);
nlp->nlp_jstat->js_start_time = nlp->nlp_jstat->js_start_ltime;
nlp->nlp_jstat->js_chkpnt_time = nlp->nlp_cdate;
if (!session->ns_data.dd_abort) {
@@ -1212,47 +1163,47 @@
if (ndmp_write_utf8magic(cmds->tcs_command) < 0) {
backup_release_structs(session);
return (-1);
}
- NDMP_LOG(LOG_DEBUG, "Backing up \"%s\" started.",
+ syslog(LOG_DEBUG, "Backing up \"%s\" started.",
nlp->nlp_backup_path);
err = ndmp_backup_reader(cmds, nlp, jname);
if (err != 0) {
backup_release_structs(session);
- NDMP_LOG(LOG_DEBUG, "Launch ndmp_backup_reader: %s",
+ syslog(LOG_DEBUG, "Launch ndmp_backup_reader: %s",
strerror(err));
return (-1);
}
/* Act as the writer thread. */
err = ndmp_tar_writer(session, mod_params, cmds);
nlp->nlp_jstat->js_stop_time = time(NULL);
- NDMP_LOG(LOG_DEBUG,
- "Runtime [%s] %llu bytes (%llu): %d seconds",
+ syslog(LOG_DEBUG,
+ "Runtime [%s] %lu bytes (%llu): %d seconds",
nlp->nlp_backup_path, session->ns_mover.md_data_written,
session->ns_mover.md_data_written,
nlp->nlp_jstat->js_stop_time -
nlp->nlp_jstat->js_start_ltime);
MOD_LOG(mod_params,
- "Runtime [%s] %llu bytes (%llu): %d seconds",
+ "Runtime [%s] %lu bytes (%lu): %d seconds",
nlp->nlp_backup_path, session->ns_mover.md_data_written,
session->ns_mover.md_data_written,
nlp->nlp_jstat->js_stop_time -
nlp->nlp_jstat->js_start_ltime);
if (session->ns_data.dd_abort)
err = -1;
- NDMP_LOG(LOG_DEBUG, "Backing up \"%s\" finished. (%d)",
+ syslog(LOG_DEBUG, "Backing up \"%s\" finished. (%d)",
nlp->nlp_backup_path, err);
} else {
nlp->nlp_jstat->js_stop_time = time(NULL);
- NDMP_LOG(LOG_DEBUG, "Backing up \"%s\" aborted.",
+ syslog(LOG_DEBUG, "Backing up \"%s\" aborted.",
nlp->nlp_backup_path);
err = 0;
}
backup_release_structs(session);
@@ -1279,12 +1230,10 @@
ndmp_name *ent;
pthread_t rdtp, wrtp;
int i;
if (mod_params->mp_operation != NDMP_DATA_OP_RECOVER) {
- NDMP_LOG(LOG_DEBUG,
- "mod_params->mp_operation != NDMP_DATA_OP_RECOVER");
return (-1);
}
if (nlp->nlp_restore_path[0] != '\0')
rspath = nlp->nlp_restore_path;
@@ -1291,13 +1240,16 @@
else if (nlp->nlp_restore_bk_path[0] != '\0')
rspath = nlp->nlp_restore_bk_path;
else
rspath = "";
- (void) ndmp_new_job_name(jname);
- if (restore_create_structs(session, jname) < 0)
+ if (ndmp_new_job_name(jname, sizeof (jname)) <= 0) {
return (-1);
+ }
+ if (restore_create_structs(session, jname) < 0) {
+ return (-1);
+ }
nlp->nlp_jstat->js_start_ltime = time(NULL);
nlp->nlp_jstat->js_start_time = time(NULL);
if (!session->ns_data.dd_abort) {
@@ -1304,12 +1256,12 @@
cmds = &nlp->nlp_cmds;
cmds->tcs_reader = cmds->tcs_writer = TLM_RESTORE_RUN;
cmds->tcs_command->tc_reader = TLM_RESTORE_RUN;
cmds->tcs_command->tc_writer = TLM_RESTORE_RUN;
- NDMP_LOG(LOG_DEBUG, "Restoring to \"%s\" started.", rspath);
- NDMP_LOG(LOG_DEBUG, "Restoring from %s tape(s).",
+ syslog(LOG_DEBUG, "Restoring to \"%s\" started.", rspath);
+ syslog(LOG_DEBUG, "Restoring from %s tape(s).",
ndmp_data_get_mover_mode(session));
arg.tr_session = session;
arg.tr_mod_params = mod_params;
arg.tr_cmds = cmds;
@@ -1317,18 +1269,18 @@
err = pthread_create(&rdtp, NULL, (funct_t)ndmp_tar_reader,
(void *)&arg);
if (err == 0) {
tlm_cmd_wait(cmds->tcs_command, TLM_TAR_READER);
} else {
- NDMP_LOG(LOG_DEBUG, "Launch ndmp_tar_reader: %m");
+ syslog(LOG_DEBUG, "Launch ndmp_tar_reader: %m");
return (-1);
}
if (!ndmp_check_utf8magic(cmds->tcs_command)) {
- NDMP_LOG(LOG_DEBUG, "UTF8Magic not found!");
+ syslog(LOG_DEBUG, "UTF8Magic not found!");
} else {
- NDMP_LOG(LOG_DEBUG, "UTF8Magic found");
+ syslog(LOG_DEBUG, "UTF8Magic found");
}
(void) memset(&tlm_arg, 0, sizeof (tlm_backup_restore_arg_t));
(void) pthread_barrier_init(&tlm_arg.ba_barrier, 0, 2);
@@ -1339,28 +1291,28 @@
tlm_arg.ba_cmd = cmds->tcs_command;
tlm_arg.ba_job = nlp->nlp_jstat->js_job_name;
tlm_arg.ba_dir = nlp->nlp_restore_path;
for (i = 0; i < nlp->nlp_nfiles; i++) {
ent = (ndmp_name *)MOD_GETNAME(mod_params, i);
- tlm_arg.ba_sels[i] = ent->name;
+ tlm_arg.ba_sels[i] = strdup(ent->name);
}
+ tlm_arg.ba_count = i;
-
if (tm_tar_ops.tm_getfile != NULL) {
err = pthread_create(&wrtp, NULL,
(funct_t)tm_tar_ops.tm_getfile, (void *)&tlm_arg);
} else {
(void) pthread_barrier_destroy(&tlm_arg.ba_barrier);
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_DEBUG,
"Thread create tm_getfile: ops NULL");
return (-1);
}
if (err == 0) {
(void) pthread_barrier_wait(&tlm_arg.ba_barrier);
} else {
(void) pthread_barrier_destroy(&tlm_arg.ba_barrier);
- NDMP_LOG(LOG_DEBUG, "thread create tm_getfile: %m");
+ syslog(LOG_DEBUG, "thread create tm_getfile: %m");
return (-1);
}
(void) pthread_join(rdtp, NULL);
(void) pthread_join(wrtp, NULL);
@@ -1372,18 +1324,18 @@
(void) send_unrecovered_list(mod_params, nlp);
ndmp_stop_local_reader(session, cmds);
ndmp_wait_for_reader(cmds);
ndmp_stop_remote_reader(session);
- NDMP_LOG(LOG_DEBUG, "Restoring to \"%s\" finished. (%d)",
+ syslog(LOG_DEBUG, "Restoring to \"%s\" finished. (%d)",
rspath, err);
} else {
nlp->nlp_jstat->js_stop_time = time(NULL);
/* nothing restored. */
(void) send_unrecovered_list(mod_params, nlp);
- NDMP_LOG(LOG_DEBUG, "Restoring to \"%s\" aborted.",
+ syslog(LOG_DEBUG, "Restoring to \"%s\" aborted.",
rspath);
err = -1;
}
NDMP_FREE(nlp->nlp_restore_path);
@@ -1504,13 +1456,13 @@
rv = 0;
/* Append the backup path to all the "ent[].name"s. */
for (i = 0; i < n; i++) {
ent = (ndmp_name *)MOD_GETNAME(params, i);
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_DEBUG,
"Old: ent[%d].name: \"%s\"", i, ent->name);
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_DEBUG,
"Old: ent[%d].dest: \"%s\"", i, ent->dest);
/* remove trailing slash */
len = strlen(ent->name);
if (ent->name[len - 1] == '/')
@@ -1530,11 +1482,11 @@
break;
}
free(ent->name);
ent->name = cp;
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_DEBUG,
"New: ent[%d].name: \"%s\"", i, ent->name);
}
free(pathname);
return (rv);
@@ -1553,20 +1505,20 @@
int i, rv;
ndmp_name *ent;
rv = 0;
if (rspath != NULL && *rspath != '\0') {
- NDMP_LOG(LOG_DEBUG, "rspath: \"%s\"", rspath);
+ syslog(LOG_DEBUG, "rspath: \"%s\"", rspath);
if (!fs_volexist(rspath)) {
MOD_LOG(params,
"Error: Invalid volume name for restore.");
rv = -1;
}
} else {
for (i = 0; i < n; i++) {
ent = (ndmp_name *)MOD_GETNAME(params, i);
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_DEBUG,
"ent[%d].name: \"%s\"", i, ent->name);
if (!fs_volexist(ent->name)) {
MOD_LOG(params,
"Error: Invalid volume name for restore.",
@@ -1639,31 +1591,31 @@
nlp->nlp_backup_path)) != NDMP_NO_ERR)
return (rv);
/* Should the st_ctime be ignored when backing up? */
if (ndmp_ignore_ctime) {
- NDMP_LOG(LOG_DEBUG, "ignoring st_ctime");
+ syslog(LOG_DEBUG, "ignoring st_ctime");
NLP_SET(nlp, NLPF_IGNCTIME);
} else
NLP_UNSET(nlp, NLPF_IGNCTIME);
/* Should the st_lmtime be ignored when backing up? */
if (ndmp_include_lmtime) {
- NDMP_LOG(LOG_DEBUG, "including st_lmtime");
+ syslog(LOG_DEBUG, "including st_lmtime");
NLP_SET(nlp, NLPF_INCLMTIME);
} else
NLP_UNSET(nlp, NLPF_INCLMTIME);
- NDMP_LOG(LOG_DEBUG, "flags %x", nlp->nlp_flags);
+ syslog(LOG_DEBUG, "flags %x", nlp->nlp_flags);
/* Is backup history requested? */
cp = MOD_GETENV(params, "HIST");
if (cp == NULL) {
- NDMP_LOG(LOG_DEBUG, "env(HIST) not specified");
+ syslog(LOG_DEBUG, "env(HIST) not specified");
NLP_UNSET(nlp, NLPF_FH);
} else {
- NDMP_LOG(LOG_DEBUG, "env(HIST): \"%s\"", cp);
+ syslog(LOG_DEBUG, "env(HIST): \"%s\"", cp);
if (strchr("t_ty_y", *cp))
NLP_SET(nlp, NLPF_FH);
else
NLP_UNSET(nlp, NLPF_FH);
@@ -1671,14 +1623,14 @@
nlp->nlp_clevel = 0;
/* Is it an incremental backup? */
cp = MOD_GETENV(params, "LEVEL");
if (cp == NULL) {
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_DEBUG,
"env(LEVEL) not specified, default to 0");
} else if (*cp < '0' || *cp > '9' || *(cp+1) != '\0') {
- NDMP_LOG(LOG_DEBUG, "Invalid backup level '%s'", cp);
+ syslog(LOG_DEBUG, "Invalid backup level '%s'", cp);
return (NDMP_ILLEGAL_ARGS_ERR);
} else
nlp->nlp_clevel = *cp - '0';
/* Extract last backup time from the dumpdates file */
@@ -1689,25 +1641,25 @@
MOD_LOG(params, "Error: getting dumpdate for %s level %d\n",
nlp->nlp_backup_path, nlp->nlp_clevel);
return (NDMP_NO_MEM_ERR);
}
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_DEBUG,
"Date of this level %d on \"%s\": %s",
nlp->nlp_clevel, nlp->nlp_backup_path, cctime(&nlp->nlp_cdate));
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_DEBUG,
"Date of last level %d on \"%s\": %s",
nlp->nlp_llevel, nlp->nlp_backup_path, cctime(&nlp->nlp_ldate));
/* Should the dumpdate file be updated? */
cp = MOD_GETENV(params, "UPDATE");
if (cp == NULL) {
- NDMP_LOG(LOG_DEBUG,
+ syslog(LOG_DEBUG,
"env(UPDATE) not specified, default to TRUE");
NLP_SET(nlp, NLPF_UPDATE);
} else {
- NDMP_LOG(LOG_DEBUG, "env(UPDATE): \"%s\"", cp);
+ syslog(LOG_DEBUG, "env(UPDATE): \"%s\"", cp);
if (strchr("t_ty_y", *cp) != NULL)
NLP_SET(nlp, NLPF_UPDATE);
else
NLP_UNSET(nlp, NLPF_UPDATE);
}
@@ -1770,11 +1722,11 @@
if (strncmp(s, t, tlen) == 0 && s[slen - 1] == '/')
rv = TRUE;
}
}
- NDMP_LOG(LOG_DEBUG, "rv: %d", rv);
+ syslog(LOG_DEBUG, "rv: %d", rv);
return (rv);
}
/*
@@ -1795,11 +1747,10 @@
{
char *bkpath, *rspath;
ndmp_lbr_params_t *nlp;
if ((nlp = ndmp_get_nlp(session)) == NULL) {
- NDMP_LOG(LOG_DEBUG, "nlp == NULL");
return (-1);
}
/* Extract directory from where the backup was made. */
if ((bkpath = get_backup_path_v2(params)) == NULL)
@@ -1809,11 +1760,11 @@
/* The number of the selections. */
if ((nlp->nlp_nfiles = get_nfiles(session, params)) == 0)
return (NDMP_ILLEGAL_ARGS_ERR);
- NDMP_LOG(LOG_DEBUG, "nfiles: %d", nlp->nlp_nfiles);
+ syslog(LOG_DEBUG, "nfiles: %d", nlp->nlp_nfiles);
if ((rspath = get_restore_dest(params)) == NULL)
return (NDMP_ILLEGAL_ARGS_ERR);
if (fs_is_rdonly(rspath)) {
@@ -1876,30 +1827,28 @@
fs_is_rdonly(nlp->nlp_backup_path) ||
!fs_is_chkpnt_enabled(nlp->nlp_backup_path))
NLP_SET(nlp, NLPF_CHKPNTED_PATH);
else {
NLP_UNSET(nlp, NLPF_CHKPNTED_PATH);
- if (ndmp_create_snapshot(nlp->nlp_backup_path,
- nlp->nlp_jstat->js_job_name) < 0) {
+ if (backup_dataset_create(nlp) < 0) {
MOD_LOG(mod_params,
"Error: creating checkpoint on %s\n",
nlp->nlp_backup_path);
/* -1 causes halt reason to become internal error. */
err = -1;
}
}
- NDMP_LOG(LOG_DEBUG, "NLPF_CHKPNTED_PATH: %c",
+ syslog(LOG_DEBUG, "NLPF_CHKPNTED_PATH: %c",
NDMP_YORN(NLP_ISCHKPNTED(nlp)));
- NDMP_LOG(LOG_DEBUG, "err: %d, update %c",
+ syslog(LOG_DEBUG, "err: %d, update %c",
err, NDMP_YORN(NLP_SHOULD_UPDATE(nlp)));
if (err == 0) {
- err = ndmp_get_cur_bk_time(nlp, &nlp->nlp_cdate,
- nlp->nlp_jstat->js_job_name);
+ err = ndmp_get_cur_bk_time(nlp, &nlp->nlp_cdate);
if (err != 0) {
- NDMP_LOG(LOG_DEBUG, "err %d", err);
+ syslog(LOG_DEBUG, "err %d", err);
} else {
log_bk_params_v2(session, mod_params, nlp);
err = ndmpd_tar_backup(session, mod_params, nlp);
}
}
@@ -1908,14 +1857,13 @@
(void) dbm_free(nlp->nlp_bkmap);
nlp->nlp_bkmap = -1;
}
if (!NLP_ISCHKPNTED(nlp))
- (void) ndmp_remove_snapshot(nlp->nlp_backup_path,
- nlp->nlp_jstat->js_job_name);
+ (void) backup_dataset_destroy(nlp);
- NDMP_LOG(LOG_DEBUG, "err %d, update %c",
+ syslog(LOG_DEBUG, "err %d, update %c",
err, NDMP_YORN(NLP_SHOULD_UPDATE(nlp)));
if (err == 0 && NLP_SHOULD_UPDATE(nlp)) {
if (ndmpd_put_dumptime(nlp->nlp_backup_path, nlp->nlp_clevel,
nlp->nlp_cdate) < 0) {