Esempio n. 1
0
/*
 * ndmpd_abort_making_v2
 *
 * Abort the process of marking inodes.
 *
 * Parameters:
 *   session (input) - pointer to the session
 *
 * Returns:
 *   void
 */
void
ndmpd_abort_marking_v2(ndmpd_session_t *session)
{
    ndmp_lbr_params_t *nlp;

    nlp = ndmp_get_nlp(session);
    if (nlp)
        NLP_SET(nlp, NLPF_ABORTED);
}
Esempio n. 2
0
/*
 * ndmpd_fhnode_v3_cb
 *
 * Callback function for file history node information
 */
int
ndmpd_fhnode_v3_cb(lbr_fhlog_call_backs_t *cbp, char *dir, char *file,
    struct stat64 *stp, u_longlong_t off)
{
	int err;
	ulong_t ino;
	ndmp_lbr_params_t *nlp;
	ndmpd_module_params_t *params;

	if (!cbp) {
		err = -1;
		syslog(LOG_DEBUG, "cbp is NULL");
	} else if (!cbp->fh_cookie) {
		err = -1;
		syslog(LOG_DEBUG, "cookie is NULL");
	} else if (!dir) {
		err = -1;
		syslog(LOG_DEBUG, "dir is NULL");
	} else if (!file) {
		err = -1;
		syslog(LOG_DEBUG, "file is NULL");
	} else if (!stp) {
		err = -1;
		syslog(LOG_DEBUG, "stp is NULL");
	} else if (!(nlp = ndmp_get_nlp(cbp->fh_cookie))) {
		err = -1;
		syslog(LOG_DEBUG, "nlp is NULL");
	} else {
		err = 0;
	}

	if (err != 0)
		return (0);


	err = 0;
	if (NLP_ISSET(nlp, NLPF_FH)) {
		if (!NLP_ISSET(nlp, NLPF_DIRECT))
			off = 0LL;
		if (stp->st_ino == nlp->nlp_bkdirino) {
			ino = ROOT_INODE;
			syslog(LOG_DEBUG,
			    "bkroot %d -> %d", stp->st_ino, ROOT_INODE);
		} else
			ino = stp->st_ino;

		params = nlp->nlp_params;
		if (!params || !params->mp_file_history_node_func)
			err = -1;
		else if ((err = (*params->mp_file_history_node_func)(cbp->
		    fh_cookie, ino, stp, off)) < 0)
			syslog(LOG_ERR, "\"%s/%s\" %d", dir, file, err);
	}

	return (err);
}
Esempio n. 3
0
/*
 * get_params
 *
 * Callbacks from LBR.
 */
static ndmpd_module_params_t *
get_params(void *cookie)
{
	ndmp_lbr_params_t *nlp;

	if ((nlp = ndmp_get_nlp(cookie)) == NULL)
		return (NULL);

	return (nlp->nlp_params);
}
Esempio n. 4
0
/*
 * backup_create_structs
 *
 * Allocate the structures before performing backup
 *
 * Parameters:
 *   sesison (input) - session handle
 *   jname (input) - backup job name
 *
 * Returns:
 *   0: on success
 *  -1: otherwise
 */
static int
backup_create_structs(ndmpd_session_t *session, char *jname)
{
	int n;
	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);
	if (xfer_size < 512*KILOBYTE) {
		/*
		 * Read multiple of mover_record_size near to 512K.  This
		 * will prevent the data being copied in the mover buffer
		 * 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);
	}

	cmds->tcs_command = tlm_create_reader_writer_ipc(TRUE, xfer_size);
	if (cmds->tcs_command == NULL) {
		NDMP_LOG(LOG_DEBUG, "Error creating ipc buffers");
		tlm_un_ref_job_stats(jname);
		return (-1);
	}

	nlp->nlp_logcallbacks = lbrlog_callbacks_init(session,
	    ndmpd_file_history_path,
	    ndmpd_file_history_dir,
	    ndmpd_file_history_node);
	if (nlp->nlp_logcallbacks == NULL) {
		tlm_release_reader_writer_ipc(cmds->tcs_command);
		tlm_un_ref_job_stats(jname);
		return (-1);
	}
	nlp->nlp_jstat->js_callbacks = (void *)(nlp->nlp_logcallbacks);

	return (0);
}
Esempio n. 5
0
/*ARGSUSED*/
int
ndmpd_file_history_node(lbr_fhlog_call_backs_t *cbp, char *dir, char *file,
    struct stat64 *stp, u_longlong_t off)
{
	int err;
	ulong_t ino;
	ndmp_lbr_params_t *nlp;
	ndmpd_module_params_t *params;

	if (!cbp) {
		err = -1;
		syslog(LOG_DEBUG, "cbp is NULL");
	} else if (!cbp->fh_cookie) {
		err = -1;
		syslog(LOG_DEBUG, "cookie is NULL");
	} else if (!dir) {
		err = -1;
		syslog(LOG_DEBUG, "dir is NULL");
	} else if (!file) {
		err = -1;
		syslog(LOG_DEBUG, "file is NULL");
	} else if (!stp) {
		err = -1;
		syslog(LOG_DEBUG, "stp is NULL");
	} else if (!(nlp = ndmp_get_nlp(cbp->fh_cookie))) {
		err = -1;
		syslog(LOG_DEBUG, "nlp is NULL");
	} else
		err = 0;

	if (err != 0)
		return (0);

	err = 0;
	if (fh_requested(cbp->fh_cookie) == TRUE) {
		if (stp->st_ino == nlp->nlp_bkdirino) {
			ino = ROOT_INODE;
			syslog(LOG_DEBUG,
			    "bkroot %d -> %d", stp->st_ino, ROOT_INODE);
		} else {
			ino = stp->st_ino;
		}

		params = get_params(cbp->fh_cookie);
		if (params == NULL || params->mp_file_history_node_func == NULL)
			err = -1;
		else if ((err = (*params->mp_file_history_node_func)(cbp->
		    fh_cookie, ino, stp, 0)) < 0)
			syslog(LOG_DEBUG, "\"%s/\": %d", dir, file, err);

	}

	return (err);
}
Esempio n. 6
0
/*
 * fh_requested
 *
 * Check in LB parameters if file history is requested
 */
static boolean_t
fh_requested(void *cookie)
{
	ndmp_lbr_params_t *nlp;

	if ((nlp = ndmp_get_nlp(cookie)) == NULL) {
		syslog(LOG_DEBUG, "nlp is NULL");
		return (FALSE);
	}

	syslog(LOG_DEBUG, "nlp_fh %c", NDMP_YORN(NLP_ISSET(nlp, NLPF_FH)));

	return (NLP_ISSET(nlp, NLPF_FH));
}
Esempio n. 7
0
/*
 * restore_create_structs
 *
 * Allocate structures for performing a restore
 *
 * Parameters:
 *   sesison (input) - session handle
 *   jname (input) - backup job name
 *
 * Returns:
 *   0: on success
 *  -1: otherwise
 */
static int
restore_create_structs(ndmpd_session_t *session, char *jname)
{
	int i;
	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");
		tlm_un_ref_job_stats(jname);
		return (-1);
	}

	nlp->nlp_logcallbacks = lbrlog_callbacks_init(session,
	    ndmpd_path_restored, NULL, NULL);
	if (nlp->nlp_logcallbacks == NULL) {
		tlm_release_reader_writer_ipc(cmds->tcs_command);
		tlm_un_ref_job_stats(jname);
		return (-1);
	}
	nlp->nlp_jstat->js_callbacks = (void *)(nlp->nlp_logcallbacks);

	nlp->nlp_restored = ndmp_malloc(sizeof (boolean_t) * nlp->nlp_nfiles);
	if (nlp->nlp_restored == NULL) {
		lbrlog_callbacks_done(nlp->nlp_logcallbacks);
		tlm_release_reader_writer_ipc(cmds->tcs_command);
		tlm_un_ref_job_stats(jname);
		return (-1);
	}
	for (i = 0; i < (int)nlp->nlp_nfiles; i++)
		nlp->nlp_restored[i] = FALSE;

	return (0);
}
Esempio n. 8
0
/*
 * ndmpd_fhpath_v3_cb
 *
 * Callback function for file history path information
 */
int
ndmpd_fhpath_v3_cb(lbr_fhlog_call_backs_t *cbp, char *path, struct stat64 *stp,
    u_longlong_t off)
{
	int err;
	ndmp_lbr_params_t *nlp;
	ndmpd_module_params_t *params;

	if (!cbp) {
		err = -1;
		syslog(LOG_DEBUG, "cbp is NULL");
	} else if (!cbp->fh_cookie) {
		err = -1;
		syslog(LOG_DEBUG, "cookie is NULL");
	} else if (!path) {
		err = -1;
		syslog(LOG_DEBUG, "path is NULL");
	} else if (!(nlp = ndmp_get_nlp(cbp->fh_cookie))) {
		err = -1;
		syslog(LOG_DEBUG, "nlp is NULL");
	} else
		err = 0;

	if (err != 0)
		return (0);

	err = 0;
	if (NLP_ISSET(nlp, NLPF_FH)) {
		if (!NLP_ISSET(nlp, NLPF_DIRECT)) {
			syslog(LOG_DEBUG, "DAR NOT SET!");
			off = 0LL;
		}

		params = get_params(cbp->fh_cookie);
		if (!params || !params->mp_file_history_path_func) {
			err = -1;
		} else {
			char *p =
			    ndmp_get_relative_path(get_backup_path_v3(params),
			    path);
			if ((err = ndmpd_api_file_history_file_v3(cbp->
			    fh_cookie, p, stp, off)) < 0)
				syslog(LOG_DEBUG, "\"%s\" %d", path, err);
		}
	}

	return (err);
}
Esempio n. 9
0
/*ARGSUSED*/
int
ndmpd_path_restored_v3(lbr_fhlog_call_backs_t *cbp, char *name,
    struct stat64 *st, u_longlong_t ll_idx)
{
	int rv;
	ndmp_lbr_params_t *nlp;
	ndmpd_module_params_t *params;
	int idx = (int)ll_idx;

	if (!cbp) {
		syslog(LOG_DEBUG, "cbp is NULL");
		return (-1);
	}
	if (!name) {
		syslog(LOG_DEBUG, "name is NULL");
		return (-1);
	}

	nlp = ndmp_get_nlp(cbp->fh_cookie);
	if (!nlp) {
		syslog(LOG_DEBUG, "nlp is NULL");
		return (-1);
	}
	if (idx < 0 || idx >= nlp->nlp_nfiles) {
		syslog(LOG_DEBUG, "Invalid idx: %d", idx);
		return (-1);
	}
	params = nlp->nlp_params;
	if (!params || !params->mp_file_recovered_func)
		return (-1);

	if (nlp->nlp_lastidx == -1)
		nlp->nlp_lastidx = idx;

	rv = 0;
	(void) bm_setone(nlp->nlp_rsbm, (u_longlong_t)idx);
	/*
	 * Note: We should set the nm3_err here.
	 */
	if (nlp->nlp_lastidx != idx) {
		rv = ndmp_send_recovery_stat_v3(params, nlp, nlp->nlp_lastidx,
		    0);
		nlp->nlp_lastidx = idx;
	}

	return (rv);
}
Esempio n. 10
0
/*ARGSUSED*/
static void
backup_release_structs(ndmpd_session_t *session)
{
	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;
	}

	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");
	}
}
Esempio n. 11
0
/*ARGSUSED*/
int
ndmpd_path_restored(lbr_fhlog_call_backs_t *cbp, char *name, struct stat64 *stp,
    u_longlong_t ll_pos)
{
	int rv;
	ndmp_name *entp;
	ndmp_lbr_params_t *nlp;
	ndmpd_module_params_t *params;
	int pos =  (int)ll_pos;

	if (cbp == NULL) {
		syslog(LOG_DEBUG, "cbp is NULL");
		return (-1);
	}
	if (name == NULL) {
		syslog(LOG_DEBUG, "name is NULL");
		return (-1);
	}

	if ((nlp = ndmp_get_nlp(cbp->fh_cookie)) == NULL) {
		syslog(LOG_DEBUG, "nlp is NULL");
		return (-1);
	}
	if (pos < 0 || pos >= nlp->nlp_nfiles) {
		syslog(LOG_DEBUG, "Invalid pos: %d", pos);
		return (-1);
	}
	params = get_params(cbp->fh_cookie);
	if (params == NULL || params->mp_file_recovered_func == NULL)
		return (-1);

	rv = 0;
	if (!nlp->nlp_restored[pos]) {
		entp = (ndmp_name *)MOD_GETNAME(params, pos);
		if (entp && entp->name)
			name = entp->name;

		if ((rv = MOD_FILERECOVERD(params, name, 0)) >= 0)
			nlp->nlp_restored[pos] = TRUE;
	}

	return (rv);
}
Esempio n. 12
0
int
ndmpd_tar_restore_starter(void *arg)
{
	ndmpd_module_params_t *mod_params = arg;
	int err;
	ndmpd_session_t *session;
	ndmp_lbr_params_t *nlp;

	session = (ndmpd_session_t *)(mod_params->mp_daemon_cookie);
	*(mod_params->mp_module_cookie) = nlp = ndmp_get_nlp(session);
	ndmp_session_ref(session);

	err = ndmpd_tar_restore(session, mod_params, nlp);
	MOD_DONE(mod_params, err);

	/* nlp_params is allocated in start_recover() */
	NDMP_FREE(nlp->nlp_params);

	NS_DEC(nrs);
	ndmp_session_unref(session);
	return (err);
}
Esempio n. 13
0
/*
 * mark_cb
 *
 * The callback function, called by traverse_post to mark bits
 * in the bitmap.
 *
 * Set the bit of the entry if it's been modified (obviously
 * should be backed up) plus its parent directory.
 *
 * If the entry is a directory and is not modified itself,
 * but it's marked, then there is something below it that
 * is being backed up.  It shows the the path, leads to
 * an object that will be backed up. So the path should
 * be marked too.
 *
 * The backup path itself is always marked.
 *
 * Parameters:
 *   arg (input) - pointer to the mark parameter
 *   pnp (input) - pointer to the path node
 *   enp (input) - pointer to the entry node
 *
 * Returns:
 *   0: as long as traversing should continue
 *   != 0: if traversing should stop
 */
int
mark_cb(void *arg, fst_node_t *pnp, fst_node_t *enp)
{
    int bmd;
    int rv;
    u_longlong_t bl;
    time_t ddate;
    fs_fhandle_t *pfhp, *efhp;
    struct stat64 *pstp, *estp;
    mark_param_t *mpp;
    ndmp_lbr_params_t *nlp;
    tlm_acls_t *tacl;

    rv = 0;
    mpp = (mark_param_t *)arg;
    tacl = mpp->mp_tacl;
    nlp = ndmp_get_nlp(mpp->mp_session);
    if (!mpp) {
        syslog(LOG_ERR, "NULL argument passed");
        rv = -1;
    } else if (mpp->mp_session->ns_eof) {
        syslog(LOG_INFO, "Connection to the client is closed");
        rv = -1;
    } else if (mpp->mp_session->ns_data.dd_abort ||
               (nlp && NLP_ISSET(nlp, NLPF_ABORTED))) {
        syslog(LOG_INFO, "Processing directories aborted.");
        rv = -1;
    }

    if (rv != 0)
        return (rv);

    ddate = mpp->mp_ddate;
    bmd = mpp->mp_bmd;
    bl = dbm_getlen(bmd);

    pfhp = pnp->tn_fh;
    pstp = pnp->tn_st;

    /* sanity check on fh and stat of the path passed */
    if (pstp->st_ino > bl) {
        syslog(LOG_ERR, "Invalid path inode #%u",
               (uint_t)pstp->st_ino);
        return (-1);
    }
    if (pstp->st_ino != pfhp->fh_fid) {
        syslog(LOG_ERR, "Path ino mismatch %u %u",
               (uint_t)pstp->st_ino, (uint_t)pfhp->fh_fid);
        return (-1);
    }

    /*
     * Always mark the backup path inode number.
     */
    if (!enp->tn_path) {
        (void) dbm_setone(bmd, pstp->st_ino);
        return (0);
    }

    efhp = enp->tn_fh;
    estp = enp->tn_st;

    /* sanity check on fh and stat of the entry passed */
    if (estp->st_ino > bl) {
        syslog(LOG_ERR, "Invalid entry inode #%u",
               (uint_t)estp->st_ino);
        return (-1);
    }
    if (estp->st_ino != efhp->fh_fid) {
        syslog(LOG_ERR, "Entry ino mismatch %u %u", estp->st_ino,
               (uint_t)pfhp->fh_fid);
        return (-1);
    }

    /* check the dates and mark the bitmap inode */
    if (ddate == 0) {
        /* base backup */
        (void) dbm_setone(bmd, (u_longlong_t)estp->st_ino);
        (void) dbm_setone(bmd, (u_longlong_t)pstp->st_ino);

    } else if (estp->st_mtime > ddate) {
        (void) dbm_setone(bmd, (u_longlong_t)estp->st_ino);
        (void) dbm_setone(bmd, (u_longlong_t)pstp->st_ino);
        if (ndmpd_verbose_traverse) {
            syslog(LOG_DEBUG,
                   "m(%u,%u,%u,%u)", (uint_t)pstp->st_ino,
                   (uint_t)estp->st_ino, (uint_t)estp->st_mtime,
                   (uint_t)ddate);
            syslog(LOG_DEBUG, "\"%s/%s\"",
                   pnp->tn_path, enp->tn_path);
        }
    } else if (iscreated(nlp, NULL, tacl, ddate)) {
        (void) dbm_setone(bmd, (u_longlong_t)estp->st_ino);
        (void) dbm_setone(bmd, (u_longlong_t)pstp->st_ino);
        if (ndmpd_verbose_traverse) {
            syslog(LOG_DEBUG,
                   "cr(%u,%u,%u,%u)", (uint_t)pstp->st_ino,
                   (uint_t)estp->st_ino, (uint_t)estp->st_mtime,
                   (uint_t)ddate);
            syslog(LOG_DEBUG, "\"%s/%s\"",
                   pnp->tn_path, enp->tn_path);
        }
    } else if (estp->st_ctime > ddate) {
        if (!NLP_IGNCTIME(nlp)) {
            (void) dbm_setone(bmd, (u_longlong_t)estp->st_ino);
            (void) dbm_setone(bmd, (u_longlong_t)pstp->st_ino);
        }
        if (ndmpd_verbose_traverse) {
            if (NLP_IGNCTIME(nlp)) {
                syslog(LOG_DEBUG,
                       "ign c(%u,%u,%u,%u)", (uint_t)pstp->st_ino,
                       (uint_t)estp->st_ino,
                       (uint_t)estp->st_ctime, (uint_t)ddate);
            } else {
                syslog(LOG_DEBUG,
                       "c(%u,%u,%u,%u)", (uint_t)pstp->st_ino,
                       (uint_t)estp->st_ino,
                       (uint_t)estp->st_ctime, (uint_t)ddate);
            }
            syslog(LOG_DEBUG, "\"%s/%s\"",
                   pnp->tn_path, enp->tn_path);
        }
    } else if (S_ISDIR(estp->st_mode) &&
               dbm_getone(bmd, (u_longlong_t)estp->st_ino)) {
        (void) dbm_setone(bmd, (u_longlong_t)pstp->st_ino);
    }

    return (0);
}
Esempio n. 14
0
/*
 * ndmpd_fhdir_v3_cb
 *
 * Callback function for file history dir information
 */
int
ndmpd_fhdir_v3_cb(lbr_fhlog_call_backs_t *cbp, char *dir, struct stat64 *stp)
{
	char nm[PATH_MAX+1];
	int nml;
	int err;
	ulong_t ino, pino;
	ulong_t pos;
	ndmp_lbr_params_t *nlp;
	ndmpd_module_params_t *params;
	DIR *dirp;
	char dirpath[PATH_MAX];

	if (!cbp) {
		err = -1;
		syslog(LOG_DEBUG, "cbp is NULL");
	} else if (!cbp->fh_cookie) {
		err = -1;
		syslog(LOG_DEBUG, "cookie is NULL");
	} else if (!dir) {
		err = -1;
		syslog(LOG_DEBUG, "dir is NULL");
	} else if (!(nlp = ndmp_get_nlp(cbp->fh_cookie))) {
		err = -1;
		syslog(LOG_DEBUG, "nlp is NULL");
	} else
		err = 0;

	if (err != 0)
		return (0);

	if (!NLP_ISSET(nlp, NLPF_FH))
		return (0);

	/*
	 * Veritas net_backup accepts only 2 as the inode number of the backup
	 * root directory.  The other way compares the path against the
	 * backup path which is slower.
	 */
	if (stp->st_ino == nlp->nlp_bkdirino)
		pino = ROOT_INODE;
	else
		pino = stp->st_ino;

	/*
	 * There is nothing below this directory to be backed up.
	 * If there was, the bit for this directory would have
	 * been set.  Backup root directory is exception.  We
	 * always send the dir file history records of it.
	 */
	if (pino != ROOT_INODE &&
	    !dbm_getone(nlp->nlp_bkmap, (u_longlong_t)stp->st_ino)) {
		syslog(LOG_DEBUG, "nothing below here");
		return (0);
	}

	params = nlp->nlp_params;
	if (!params || !params->mp_file_history_dir_func)
		return (-1);

	pos = 0;
	err = 0;

	dirp = opendir(dir);
	if (dirp == NULL)
		return (0);

	do {
		nml = PATH_MAX;
		err = dp_readdir(dirp, &pos, nm, &nml, &ino);
		if (err != 0) {
			syslog(LOG_DEBUG,
			    "%d reading pos %u dir \"%s\"", err, pos, dir);
			break;
		}
		if (nml == 0)
			break;
		nm[nml] = '\0';

		if (pino == ROOT_INODE) {
			if (rootfs_dot_or_dotdot(nm))
				ino = ROOT_INODE;
		} else if (ino == nlp->nlp_bkdirino && IS_DOTDOT(nm)) {
			ino = ROOT_INODE;
		}

		if (!dbm_getone(nlp->nlp_bkmap, (u_longlong_t)ino))
			continue;

		/*
		 * If the entry is on exclusion list dont send the info
		 */
		if (tlm_is_excluded(dir, nm, ndmp_excl_list)) {
			syslog(LOG_DEBUG,
			    "name \"%s\" skipped", nm == 0 ? "nil" : nm);
			continue;
		}

		err = (*params->mp_file_history_dir_func)(cbp->fh_cookie, nm,
		    ino, pino);
		if (err < 0) {
			syslog(LOG_ERR, "\"%s\": %d", dir, err);
			break;
		}

		/*
		 * This is a requirement by some DMA's (net_vault) that during
		 * the incremental backup, the node info should also be sent
		 * along with the dir info for all directories leading to a
		 * backed up file.
		 */
		if (ndmp_fhinode) {
			struct stat64 ret_attr;

			(void) strlcpy(dirpath, dir, PATH_MAX);
			(void) strlcat(dirpath, "/", PATH_MAX);
			(void) strlcat(dirpath, nm, PATH_MAX);
			err = stat64(dirpath, &ret_attr);
			if (err != 0) {
				syslog(LOG_ERR,
				    "Error looking up %s", nm);
				break;
			}

			if (S_ISDIR(ret_attr.st_mode)) {
				err = (*params->mp_file_history_node_func)(cbp->
				    fh_cookie, ino, &ret_attr, 0);
				if (err < 0) {
					syslog(LOG_ERR, "\"%s/\": %d",
					    dir, err);
					break;
				}
			}
		}
	} while (err == 0);

	(void) closedir(dirp);
	return (err);
}
Esempio n. 15
0
/*
 * marklbrv3_cb
 *
 * The callback function, called by traverse_post to mark
 * bits in the bitmap.
 *
 * It's so much like mark_cb for time-based (token-based
 * and level-type) backup types, except that it looks at
 * the archive bit of the objects instead of their timestamp.
 *
 * Parameters:
 *   arg (input) - pointer to the mark parameter
 *   pnp (input) - pointer to the path node
 *   enp (input) - pointer to the entry node
 *
 * Returns:
 *   0: as long as traversing should continue
 *   != 0: if traversing should stop
 */
int
marklbrv3_cb(void *arg, fst_node_t *pnp, fst_node_t *enp)
{
    int bmd;
    u_longlong_t bl;
    fs_fhandle_t *pfhp, *efhp;
    struct stat64 *pstp, *estp;
    mark_param_t *mpp;
    ndmp_lbr_params_t *nlp;

    mpp = (mark_param_t *)arg;
    if (!mpp) {
        syslog(LOG_ERR, "NULL argument passed in marklbrv3");
        return (-1);
    }
    nlp = ndmp_get_nlp(mpp->mp_session);
    if (mpp->mp_session->ns_data.dd_abort ||
            (nlp && NLP_ISSET(nlp, NLPF_ABORTED))) {
        syslog(LOG_ERR, "Processing directories aborted.");
        return (-1);
    }

    bmd = mpp->mp_bmd;
    bl = dbm_getlen(bmd);

    pfhp = pnp->tn_fh;
    pstp = pnp->tn_st;

    /* sanity check on fh and stat of the path passed */
    if (pstp->st_ino > bl) {
        syslog(LOG_ERR, "Invalid path inode #%u",
               (uint_t)pstp->st_ino);
        return (-1);
    }
    if (pstp->st_ino != pfhp->fh_fid) {
        syslog(LOG_ERR, "Path ino mismatch %u %u",
               (uint_t)pstp->st_ino, (uint_t)pfhp->fh_fid);
        return (-1);
    }

    /*
     * Always mark the backup path inode number.
     */
    if (!enp->tn_path) {
        (void) dbm_setone(bmd, pstp->st_ino);
        return (0);
    }

    efhp = enp->tn_fh;
    estp = enp->tn_st;

    /* sanity check on fh and stat of the entry passed */
    if (estp->st_ino > bl) {
        syslog(LOG_DEBUG, "Invalid entry inode #%u",
               (uint_t)estp->st_ino);
        return (-1);
    }
    if (estp->st_ino != efhp->fh_fid) {
        syslog(LOG_DEBUG, "Entry ino mismatch %u %u", estp->st_ino,
               (uint_t)pfhp->fh_fid);
        return (-1);
    }

    if (S_ISDIR(estp->st_mode) &&
            dbm_getone(bmd, (u_longlong_t)estp->st_ino)) {
        (void) dbm_setone(bmd, (u_longlong_t)pstp->st_ino);
    }

    return (0);
}
Esempio n. 16
0
/*
 * ndmpd_tar_backup_starter (V2 only)
 *
 * The main backup starter function. It creates a snapshot if necessary
 * and calls ndmp_tar_backup to perform the actual backup. It does the cleanup
 * and release the snapshot at the end.
 */
int
ndmpd_tar_backup_starter(void *arg)
{
	ndmpd_module_params_t *mod_params = arg;
	int err;
	ndmpd_session_t *session;
	ndmp_lbr_params_t *nlp;

	session = (ndmpd_session_t *)(mod_params->mp_daemon_cookie);
	*(mod_params->mp_module_cookie) = nlp = ndmp_get_nlp(session);
	ndmp_session_ref(session);

	err = 0;
	if (fs_is_chkpntvol(nlp->nlp_backup_path) ||
	    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) {
			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",
	    NDMP_YORN(NLP_ISCHKPNTED(nlp)));
	NDMP_LOG(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);
		if (err != 0) {
			NDMP_LOG(LOG_DEBUG, "err %d", err);
		} else {
			log_bk_params_v2(session, mod_params, nlp);
			err = ndmpd_tar_backup(session, mod_params, nlp);
		}
	}

	if (nlp->nlp_bkmap >= 0) {
		(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);

	NDMP_LOG(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) {
			err = EPERM;
			MOD_LOG(mod_params,
			    "Error: updating the dumpdates file on %s\n",
			    nlp->nlp_backup_path);
		}
	}

	MOD_DONE(mod_params, err);

	/* nlp_params is allocated in start_backup() */
	NDMP_FREE(nlp->nlp_params);

	NS_DEC(nbk);
	ndmp_session_unref(session);
	return (err);
}
Esempio n. 17
0
/*
 * ndmp_restore_extract_params
 *
 * Go through the restore parameters and check them and extract them
 * by setting NLP flags and other values.
 *
 * Parameters:
 *
 * Returns:
 *   0: on success
 *  -1: otherwise
 */
int
ndmp_restore_extract_params(ndmpd_session_t *session,
    ndmpd_module_params_t *params)
{
	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)
		return (NDMP_ILLEGAL_ARGS_ERR);

	nlp->nlp_restore_bk_path = bkpath;

	/* 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);

	if ((rspath = get_restore_dest(params)) == NULL)
		return (NDMP_ILLEGAL_ARGS_ERR);

	if (fs_is_rdonly(rspath)) {
		MOD_LOG(params,
		    "Error: Can't restore to a read-only volume: \"%s\"\n",
		    rspath);
		return (NDMP_ILLEGAL_ARGS_ERR);
	}
	if (fs_is_chkpntvol(rspath)) {
		MOD_LOG(params,
		    "Error: Can't restore to a checkpoint: \"%s\"\n", rspath);
		return (NDMP_ILLEGAL_ARGS_ERR);
	}

	if (same_path(bkpath, rspath))
		rspath = "";

	if ((nlp->nlp_restore_path = strdup(rspath)) == NULL)
		return (NDMP_NO_MEM_ERR);

	bkpath = trim_name(bkpath);
	if (correct_ents(params, nlp->nlp_nfiles, bkpath) < 0) {
		free(nlp->nlp_restore_path);
		return (NDMP_ILLEGAL_ARGS_ERR);
	}

	if (check_restore_paths(params, nlp->nlp_nfiles, rspath) < 0) {
		free(nlp->nlp_restore_path);
		return (NDMP_ILLEGAL_ARGS_ERR);
	}

	MOD_LOG(params, "Restoring %d files.\n", nlp->nlp_nfiles);
	MOD_LOG(params, "Restoring to: \"%s\".\n", nlp->nlp_restore_path);
	MOD_LOG(params, "Record size: %d\n", session->ns_mover.md_record_size);

	return (NDMP_NO_ERR);
}
Esempio n. 18
0
/*
 * ndmp_backup_extract_params
 *
 * Go through the backup parameters and check the validity
 * for each one. Then set the NLP flags according to the parameters.
 */
int
ndmp_backup_extract_params(ndmpd_session_t *session,
    ndmpd_module_params_t *params)
{
	char *cp;
	int rv;
	ndmp_lbr_params_t *nlp;

	/* Extract directory to be backed up from env variables */
	if ((nlp = ndmp_get_nlp(session)) == NULL) {
		MOD_LOG(params, "Error: Internal error: nlp == NULL.\n");
		return (NDMP_ILLEGAL_ARGS_ERR);
	}
	if ((nlp->nlp_backup_path = get_backup_path_v2(params)) == NULL)
		return (NDMP_FILE_NOT_FOUND_ERR);

	if ((rv = check_backup_dir_validity(params,
	    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");
		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");
		NLP_SET(nlp, NLPF_INCLMTIME);
	} else
		NLP_UNSET(nlp, NLPF_INCLMTIME);

	NDMP_LOG(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");
		NLP_UNSET(nlp, NLPF_FH);
	} else {
		NDMP_LOG(LOG_DEBUG, "env(HIST): \"%s\"", cp);

		if (strchr("t_ty_y", *cp))
			NLP_SET(nlp, NLPF_FH);
		else
			NLP_UNSET(nlp, NLPF_FH);
	}

	nlp->nlp_clevel = 0;
	/* Is it an incremental backup? */
	cp = MOD_GETENV(params, "LEVEL");
	if (cp == NULL) {
		NDMP_LOG(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);
		return (NDMP_ILLEGAL_ARGS_ERR);
	} else
		nlp->nlp_clevel = *cp - '0';

	/* Extract last backup time from the dumpdates file */
	nlp->nlp_llevel = nlp->nlp_clevel;
	nlp->nlp_ldate = 0;
	if (ndmpd_get_dumptime(nlp->nlp_backup_path, &nlp->nlp_llevel,
	    &nlp->nlp_ldate) < 0) {
		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,
	    "Date of this level %d on \"%s\": %s",
	    nlp->nlp_clevel, nlp->nlp_backup_path, cctime(&nlp->nlp_cdate));
	NDMP_LOG(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,
		    "env(UPDATE) not specified, default to TRUE");
		NLP_SET(nlp, NLPF_UPDATE);
	} else {
		NDMP_LOG(LOG_DEBUG, "env(UPDATE): \"%s\"", cp);
		if (strchr("t_ty_y", *cp) != NULL)
			NLP_SET(nlp, NLPF_UPDATE);
		else
			NLP_UNSET(nlp, NLPF_UPDATE);
	}

	return (NDMP_NO_ERR);
}