/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* 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.
*/
#include <cstack.h>
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include "ndmpd.h"
#include <bitmap.h>
#include <traverse.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "tlm_buffers.h"
/*
* Parameter passed to traverse for marking inodes
* when traversing backup hierarchy in V2. It
* includes:
* mp_bmd: the bitmap describptor.
* mp_ddate: backup date.
* mp_session: pointer to the session structure.
* mp_nlp: pointer to the nlp.
* mp_tacl: pointer to the acl.
*/
typedef struct mark_param {
int mp_bmd;
} mark_param_t;
/*
* Set this variable to non-zero to print the inodes
* marked after traversing file system.
*/
static int ndmpd_print_inodes = 0;
/*
* Flag passed to traverse_post.
*/
static int ndmpd_mark_flags = 0;
/*
* if they are being marked.
*/
static int ndmpd_verbose_traverse = 0;
/*
* Set this flag to count the number of inodes marked
* after traversing backup hierarchy.
*/
static int ndmpd_mark_count_flag = 0;
/*
* Set this variable to non-zero value to force traversing
* backup hierarchy for tar format.
*/
static int ndmp_tar_force_traverse = 0;
/*
* Set this variable to non-zero value to skip processing
* directories both for tar and dump.
*/
static int ndmp_skip_traverse = 0;
/*
* count_bits_cb
*
* Call back for counting the set bits in the dbitmap.
*
* Parameters:
* bmd (input) - bitmap descriptor
* bn (input) - the bit number
* arg (input) - pointer to the argument
*
* Returns:
* 0: always
*/
static int
{
(*(u_longlong_t *)arg)++;
if (ndmpd_print_inodes)
}
return (0);
}
/*
* count_set_bits
*
* Count bits set in the bitmap.
*
* Parameters:
* path (input) - the backup path
* bmd (input) - bitmap descriptor
*
* Returns:
* void
*/
void
{
if (!ndmpd_mark_count_flag)
return;
cnt = 0;
}
/*
* traverse
*
* Starts the post-traverse the backup hierarchy. Checks
* for exceptional cases, like aborting operation and if
* asked, report detailed information after traversing.
*
* Parameters:
* session (input) - pointer to the session
* nlp (input) - pointer to the nlp structure
* ftp (input) - pointer to the traverse parameters
*
* Returns:
* 0: on success
* != 0: otherwise
*/
int
{
int rv;
time_t s, e;
return (-1);
}
(void) time(&s);
if (traverse_post(ftp) != 0) {
rv = -1;
NLPF_ABORTED)) {
"Traversing backup path hierarchy \"%s\"",
}
} else {
rv = 0;
(void) time(&e);
(uint_t)(e-s));
}
return (rv);
}
/*
* 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
{
int bmd;
int rv;
rv = 0;
if (!mpp) {
rv = -1;
rv = -1;
rv = -1;
}
if (rv != 0)
return (rv);
/* sanity check on fh and stat of the path passed */
return (-1);
}
return (-1);
}
/*
* Always mark the backup path inode number.
*/
return (0);
}
/* sanity check on fh and stat of the entry passed */
return (-1);
}
return (-1);
}
/* check the dates and mark the bitmap inode */
if (ddate == 0) {
/* base backup */
if (ndmpd_verbose_traverse) {
}
if (ndmpd_verbose_traverse) {
}
if (ndmpd_verbose_traverse) {
}
if (!NLP_IGNCTIME(nlp)) {
}
if (ndmpd_verbose_traverse) {
if (NLP_IGNCTIME(nlp)) {
} else {
}
}
if (ndmpd_verbose_traverse) {
}
}
return (0);
}
/*
* mark_inodes_v2
*
* Traverse the file system in post-order and mark
* all the modified objects and also directories leading
* to them.
*
* Parameters:
* session (input) - pointer to the session
* nlp (input) - pointer to the nlp structure
* path (input) - the physical path to traverse
*
* Returns:
* 0: on success.
* != 0: on error.
*/
int
{
return (-1);
}
}
/*
* create_bitmap
*
* Create a dbitmap and return its descriptor.
*
* Parameters:
* path (input) - path for which the bitmap should be created
* value (input) - the initial value for the bitmap
*
* Returns:
* the dbitmap descriptor
*/
static int
{
char *livepath;
if (fs_is_chkpntvol(path))
else
if (ninode == 0)
return (-1);
(void) ndmpd_mk_temp(bm_fname);
}
/*
* create_allset_bitmap
*
* A helper function to create a bitmap with all the
* values set to 1.
*
* Parameters:
* nlp (input) - pointer to the nlp structure
*
* Returns:
* the dbitmap descriptor
*/
static int
{
int rv;
rv = -1;
} else
rv = 0;
return (rv);
}
/*
* mark_common_v2
*
* Create the inode bitmap. If last date of the the
* backup is epoch, then all the objects should be backed
* up; there is no need to traverse the backup hierarchy
* and mark the inodes. All the bits should be marked.
*
* Otherwise, the backup hierarchy should be traversed and
* the objects should be marked.
*
* Parameters:
* session (input) - pointer to the session
* nlp (input) - pointer to the nlp structure
*
* Returns:
* 0: on success.
* != 0: on error.
*/
static int
{
int rv;
/*
* Everything is needed for full backup.
*/
return (create_allset_bitmap(nlp));
rv = 0;
rv = -1;
} else {
else
}
return (rv);
}
/*
* mark_tar_inodes_v2
*
* Create the bitmap for tar backup format.
*
* Parameters:
* session (input) - pointer to the session
* nlp (input) - pointer to the nlp structure
*
* Returns:
* 0: on success.
* != 0: on error.
*/
static int
{
int rv;
else
return (rv);
}
/*
* mark_dump_inodes_v2
*
* Create the bitmap for dump backup format.
*
* Parameters:
* session (input) - pointer to the session
* nlp (input) - pointer to the nlp structure
*
* Returns:
* 0: on success.
* != 0: on error.
*/
static int
{
}
/*
* ndmpd_mark_inodes_v2
*
* Mark the inodes of the backup hierarchy if necessary.
*
* Parameters:
* session (input) - pointer to the session
* nlp (input) - pointer to the nlp structure
*
* Returns:
* 0: on success.
* != 0: on error.
*/
int
{
int rv;
if (ndmp_skip_traverse) {
} else {
else if (NLP_ISDUMP(nlp))
else {
rv = -1;
}
}
return (rv);
}
/*
* ndmpd_abort_making_v2
*
* Abort the process of marking inodes.
*
* Parameters:
* session (input) - pointer to the session
*
* Returns:
* void
*/
void
{
if (nlp)
}
/*
* mark_tokv3
*
* Traverse the backup hierarchy and mark the bits for the
* modified objects of directories leading to a modified
* object for the token-based backup.
*
* Parameters:
* session (input) - pointer to the session
* nlp (input) - pointer to the nlp structure
* path (input) - the physical path to traverse
*
* Returns:
* 0: on success
* != 0: otherwise
*/
int
{
return (-1);
}
return (create_allset_bitmap(nlp));
return (-1);
}
}
/*
* 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
{
int bmd;
if (!mpp) {
return (-1);
}
return (-1);
}
/* sanity check on fh and stat of the path passed */
return (-1);
}
return (-1);
}
/*
* Always mark the backup path inode number.
*/
if (ndmpd_verbose_traverse) {
}
return (0);
}
/* sanity check on fh and stat of the entry passed */
return (-1);
}
return (-1);
}
if (ndmpd_verbose_traverse) {
}
}
return (0);
}
/*
* mark_lbrv3
*
* Traverse the backup hierarchy and mark the bits for the
* modified objects of directories leading to a modified
* object for the LBR-type backup.
*
* Parameters:
* session (input) - pointer to the session
* nlp (input) - pointer to the nlp structure
* path (input) - the physical path to traverse
*
* Returns:
* 0: on success
* != 0: otherwise
*/
int
{
char c;
return (-1);
}
/* full and archive backups backup everything */
if (c == 'F' || c == 'A')
return (create_allset_bitmap(nlp));
return (-1);
}
}
/*
* mark_levelv3
*
* Traverse the backup hierarchy and mark the bits for the
* modified objects of directories leading to a modified
* object for the level-type backup.
*
* Parameters:
* session (input) - pointer to the session
* nlp (input) - pointer to the nlp structure
* path (input) - the physical path to traverse
*
* Returns:
* 0: on success
* != 0: otherwise
*/
int
{
return (-1);
}
return (create_allset_bitmap(nlp));
return (-1);
}
/*
* We do not want to allocate memory for acl every time we
* process a file.
*/
}
/*
* mark_commonv3
*
* Create the inode bitmap. If last date of the the
* backup is epoch, then all the objects should be backed
* up; there is no need to traverse the backup hierarchy
* and mark the inodes. All the bits should be marked.
*
* Otherwise, the backup hierarchy should be traversed and
* the objects should be marked.
*
* Parameters:
* session (input) - pointer to the session
* nlp (input) - pointer to the nlp structure
*
* Returns:
* 0: on success.
* != 0: on error.
*/
int
{
int rv;
if (NLP_ISCHKPNTED(nlp))
else
} else {
rv = -1;
}
return (rv);
}
/*
* mark_tar_inodesv3
*
* Mark bits for tar backup format of V3. Normally, the
* backup hierarchy is not traversed for tar format
* unless it's forced by setting the ndmp_tar_force_traverse
* to a non-zero value.
*
* Parameters:
* session (input) - pointer to the session
* nlp (input) - pointer to the nlp structure
*
* Returns:
* 0: on success
* != 0: otherwise
*/
int
{
int rv;
else
return (rv);
}
/*
* ndmpd_mark_inodes_v3
*
* Mark the inodes of the backup hierarchy if necessary.
*
* Parameters:
* session (input) - pointer to the session
* nlp (input) - pointer to the nlp structure
*
* Returns:
* 0: on success.
* != 0: on error.
*/
int
{
int rv;
if (ndmp_skip_traverse) {
} else {
else if (NLP_ISDUMP(nlp)) {
} else {
rv = -1;
}
}
return (rv);
}