Skip to content

Commit

Permalink
Introduce incremental index write down in XML format (#466)
Browse files Browse the repository at this point in the history
  • Loading branch information
Atsushi Abe authored Jun 21, 2024
1 parent 06367df commit 8c8f6cc
Show file tree
Hide file tree
Showing 21 changed files with 1,320 additions and 112 deletions.
32 changes: 32 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,28 @@ AC_ARG_ENABLE([buggy_ifs],
)
AC_MSG_RESULT([$buggy_ifs])

dnl
dnl Handle --enable-xml-indent (default:no)
dnl
AC_MSG_CHECKING([whether to enable xml indentation for index])
AC_ARG_ENABLE([xml_indent],
[AS_HELP_STRING([--enable-xml-indent],[Enable XML indentation for index])],
[xml_indent=$enableval],
[xml_indent=no]
)
AC_MSG_RESULT([$xml_indent])

dnl
dnl Handle --enable-format-spec25 (default:no)
dnl
AC_MSG_CHECKING([whether to enable format spec 2.5 support or not])
AC_ARG_ENABLE([format_spec25],
[AS_HELP_STRING([--enable-format-spec25],[Support format spec 2.5])],
[format_spec25=$enableval],
[format_spec25=no]
)
AC_MSG_RESULT([$format_spec25])

dnl
dnl Handle extra compile flags for tape driver
dnl
Expand Down Expand Up @@ -499,6 +521,16 @@ then
AM_CPPFLAGS="${AM_CPPFLAGS} -DPOSIXLINK_ONLY"
fi

if test "x$xml_indent" = "xyes"
then
AM_CPPFLAGS="${AM_CPPFLAGS} -DINDENT_INDEXES"
fi

if test "x$format_spec25" = "xyes"
then
AM_CPPFLAGS="${AM_CPPFLAGS} -DFORMAT_SPEC25"
fi

dnl
dnl Specify CPU specific optimizer options for CRC calculation
dnl
Expand Down
13 changes: 13 additions & 0 deletions contrib/ut-incindex/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Unit Tests for incremental index

This is a directory for having unit tests for incremental index feature.

## How to run

### Basic operation test

1. `cd` to this directory
2. Run the basic test with `./ut-basic.sh [mount_point]`
- The test script formats a (filebackend) tape under `/tmp/ltfstape`, start ltfs and stop ltfs automatically.
- If `[mount_point]` is not specified, the script uses `/tmp/mnt`
- You can pass the specific `ltfs` binary directory with teh environmental value `LTFS_BIN_PATH`
96 changes: 96 additions & 0 deletions contrib/ut-incindex/ut-basic.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#!/bin/sh

source ./utils.sh

MOUNTPOINT='/tmp/mnt'
TAPE_PATH='/tmp/ltfstape'

if [ $# == 1 ]; then
MOUNTPOINT=$1
elif [ $# -gt 2 ]; then
MOUNTPOINT=$1
TAPE_PATH=$2
fi

# Format LTFS
FormatLTFS ${TAPE_PATH}
if [ $? != 0 ]; then
exit 1
fi

# Launch LTFS
LaunchLTFS ${MOUNTPOINT} ${TAPE_PATH}
if [ $? != 0 ]; then
exit 1
fi

# 1. CREATE DIRS
# Create a few dirs and files but all objects are handles by new dirs
echo "1. CREATE DIRS"
mkdir -p ${MOUNTPOINT}/dir1/dir11
mkdir -p ${MOUNTPOINT}/dir1/dir12
mkdir -p ${MOUNTPOINT}/dir2/dir21
mkdir -p ${MOUNTPOINT}/dir2/dir22
echo "AAA" > ${MOUNTPOINT}/dir1/file11
echo "AAA" > ${MOUNTPOINT}/dir1/dir11/file111
echo "AAA" > ${MOUNTPOINT}/dir1/dir11/file112
IncrementalSync ${MOUNTPOINT} '1.CREATE_DIRS'
if [ $? != 0 ]; then
exit 1
fi

# 2. CREATE FILES
# Create files for checking file creation and directory traverse
echo "2. CREATE FILES"
echo "AAA" > ${MOUNTPOINT}/dir1/dir11/file113
echo "AAA" > ${MOUNTPOINT}/dir1/dir12/file121
echo "AAA" > ${MOUNTPOINT}/dir2/dir22/file221
echo "AAA" > ${MOUNTPOINT}/dir2/file21
IncrementalSync ${MOUNTPOINT} '2.CREATE_FILES'
if [ $? != 0 ]; then
exit 1
fi

# 3. MODIFY FILES
# Modify contents of files. Need to check /dir2 doesn't have meta-data on the incremental index
echo "3. MODIFY FILES"
echo "BBB" > ${MOUNTPOINT}/dir1/dir11/file111
echo "BBB" > ${MOUNTPOINT}/dir2/dir22/file221
echo "BBB" > ${MOUNTPOINT}/dir1/file11
IncrementalSync ${MOUNTPOINT} '3.MODIFY_FILES'
if [ $? != 0 ]; then
exit 1
fi

# 4. MODIFY DIRS
# Modify directory's meta-data. Need to check both /dir1 and /dir1/dir11 has meta-data
# on the incremental index
echo "4. MODIFY DIRS"
AddXattr ${MOUNTPOINT}/dir1 'ut-attr1' 'val1'
echo "CCC" > ${MOUNTPOINT}/dir1/dir11/file111
IncrementalSync ${MOUNTPOINT} '4.MODIFY_DIRS'
if [ $? != 0 ]; then
exit 1
fi

# 5. DELETE FILES
echo "5. DELETE FILES"
rm ${MOUNTPOINT}/dir1/dir11/*
IncrementalSync ${MOUNTPOINT} '5.DELETE_FILES'
if [ $? != 0 ]; then
exit 1
fi

# 6. DELETE DIR
echo "5. DELETE DIR"
rm -rf ${MOUNTPOINT}/dir1/dir11
IncrementalSync ${MOUNTPOINT} '6.DELETE_DIR'
if [ $? != 0 ]; then
exit 1
fi

# Stop LTFS
StopLTFS ${MOUNTPOINT} ${TAPE_PATH}
if [ $? != 0 ]; then
exit 1
fi
197 changes: 197 additions & 0 deletions contrib/ut-incindex/utils.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
#!/bin/sh

PLATFORM=`uname`
ECHO='/bin/echo'

if [ "x${LTFS_BIN_PATH}" == 'x' ]; then
LTFS_BIN_PATH='/usr/local/bin'
fi

AddXattr()
{
if [ "x$1" == "x" ]; then
"Need to a target to set xattr"
return 1
else
TARGET=$1
fi

if [ "x$2" == "x" ]; then
"Need to a name to set xattr"
return 1
else
NAME=$2
fi

if [ "x$3" == "x" ]; then
"Need to a value to set xattr"
return 1
else
VAL=$2
fi

${ECHO} -n "Setting a xattr ${NAME} to ${TARGET} ... "
if [ "$PLATFORM" == "Darwin" ]; then
/usr/bin/xattr -w ${NAME} ${VAL} ${TARGET}
else
/usr/bin/attr -s ${NAME} -V ${VAL} ${TARGET}
fi

if [ $? == 0 ]; then
${ECHO} "Done"
return 0
else
${ECHO} "Failed"
return 1
fi

}

IncrementalSync()
{
if [ "x$1" == "x" ]; then
MOUNTPOINT='/tmp/mnt'
else
MOUNTPOINT=$1
fi

if [ "x$2" == "x" ]; then
MSG='Incremental Sync'
else
MSG=$2
fi

${ECHO} -n "Syncing LTFS (Incremental) ... "
if [ "$PLATFORM" == "Darwin" ]; then
/usr/bin/xattr -w ltfs.vendor.IBM.IncrementalSync ${MSG} ${MOUNTPOINT}
else
/usr/bin/attr -s ltfs.vendor.IBM.IncrementalSync -V ${MSG} ${MOUNTPOINT}
fi

if [ $? == 0 ]; then
${ECHO} "Done"
return 0
else
${ECHO} "Failed"
return 1
fi
}

FullSync()
{
if [ "x$1" == "x" ]; then
MOUNTPOINT='/tmp/mnt'
else
MOUNTPOINT=$1
fi

if [ "x$2" == "x" ]; then
MSG='Full Sync'
else
MSG=$2
fi

${ECHO} "Syncing LTFS (Full) ... "
if [ "$PLATFORM" == "Darwin" ]; then
/usr/bin/xattr -w ltfs.vendor.IBM.FullSync ${MSG} ${MOUNTPOINT}
else
/usr/bin/attr -s ltfs.vendor.IBM.FullSync -V ${MSG} ${MOUNTPOINT}
fi

if [ $? == 0 ]; then
${ECHO} "Done"
return 0
else
${ECHO} "Failed"
return 1
fi
}

FormatLTFS()
{
if [ "x$1" == "x" ]; then
TAPE_PATH='/tmp/ltfstape'
else
TAPE_PATH=$1
fi

if [ ! -d ${TAPE_PATH} ]; then
${ECHO} "Creating tape directory for file backend: ${TAPE_PATH}"
mkdir -p ${TAPE_PATH}
if [ $? != 0 ]; then
${ECHO} "Failed to create a tape path: ${TAPE_PATH}"
return 1
fi
fi

${ECHO} "Formatting tape directory with the file backend on ${TAPE_PATH} ... "
${LTFS_BIN_PATH}/mkltfs -f -e file -d ${TAPE_PATH}
if [ $? != 0 ]; then
${ECHO} "Failed to format a tape path: ${TAPE_PATH}"
return 1
fi

${ECHO} "Formatted the file backend on ${TAPE_PATH}"
return 0
}

LaunchLTFS()
{
if [ "x$1" == "x" ]; then
MOUNTPOINT='/tmp/mnt'
else
MOUNTPOINT=$1
fi

if [ "x$2" == "x" ]; then
TAPE_PATH='/tmp/ltfstape'
else
TAPE_PATH=$2
fi

if [ ! -d ${MOUNTPOINT} ]; then
${ECHO} "Creating mount point for LTFS: ${MOUNTPOINT}"
mkdir -p ${MOUNTPOINT}
if [ $? != 0 ]; then
${ECHO} "Failed to create a mount point"
return 1
fi
fi

if [ ! -d ${TAPE_PATH} ]; then
${ECHO} "Creating tape directory for file backend: ${TAPE_PATH}"
mkdir -p ${TAPE_PATH}
if [ $? != 0 ]; then
${ECHO} "Failed to create a tape path: ${TAPE_PATH}"
return 1
fi

${ECHO} "Formatting tape directory with the file backend"
${LTFS_BIN_PATH}/mkltfs -f -e file -d ${TAPE_PATH}
if [ $? != 0 ]; then
${ECHO} "Failed to format a tape path: ${TAPE_PATH}"
return 1
fi
fi

${ECHO} "Launching LTFS with the file backend"
${LTFS_BIN_PATH}/ltfs -o tape_backend=file -o sync_type=unmount -o devname=${TAPE_PATH} ${MOUNTPOINT}
if [ $? != 0 ]; then
${ECHO} "Failed to launch LTFS on ${MOUNTPOINT}"
return 1
fi

${ECHO} "LTFS is launched on ${MOUNTPOINT}"
return 0
}

StopLTFS()
{
if [ "x$1" == "x" ]; then
MOUNTPOINT='/tmp/mnt'
else
MOUNTPOINT=$1
fi

sudo umount ${MOUNTPOINT}
}
1 change: 1 addition & 0 deletions messages/internal_error/root.txt
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ root:table {
I5048E:string{ "Unexpected partition map in a label." }
I5049E:string{ "Unexpected blocksize in a label." }
I5050E:string{ "Unexpected compression in a label." }
I5051E:string{ "Unsupported index type is specified." }

// Special error codes
I9997E:string{ "Child process error (ltfsck/mkltfs): %s (%d)." }
Expand Down
8 changes: 8 additions & 0 deletions messages/libltfs/root.txt
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,14 @@ v
17292I:string { "Current position is (%llu, %llu), Error position is (%llu, %llu)." }
17293E:string { "UUID in the index does not match the label." }

17300I:string { "Wrote inc-index of %s (Gen = %lld, Part = %c, Pos = %lld, %s)." }
17301I:string { "Info inc-index, Gen = %lld, Full Part = %c, Full Pos = %lld, Back Part = %c, Back Pos = %lld)." }
17302E:string { "Path helper: Provided path must be an absolute path (%s)." }
17303E:string { "Unexpected value was found in the reason of inc-journal entry (%d)." }
17304E:string { "Unexpected value was provided to _xml_write_incremental_delete (%d)." }
17305E:string { "Failed to construct a path helper (push: %d)." }
17306E:string { "Failed to find a corresponded directory in path helper (push: %d)." }

// For Debug 19999I:string { "%s %s %d." }

// DO NOT place messages with IDs 20000 or higher here!
Expand Down
2 changes: 1 addition & 1 deletion src/iosched/unified.c
Original file line number Diff line number Diff line change
Expand Up @@ -2292,7 +2292,7 @@ int _unified_write_index_after_perm(int write_ret, struct unified_data *priv)
}

ltfs_set_commit_message_reason(SYNC_WRITE_PERM, priv->vol);
ret = ltfs_write_index(ltfs_ip_id(priv->vol), SYNC_WRITE_PERM, priv->vol);
ret = ltfs_write_index(ltfs_ip_id(priv->vol), SYNC_WRITE_PERM, LTFS_FULL_INDEX, priv->vol);

return ret;
}
Expand Down
1 change: 1 addition & 0 deletions src/libltfs/arch/errormap.c
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ static struct error_map fuse_error_list[] = {
{ LTFS_XML_WRONG_PART_MAP, "I5048E", EINVAL},
{ LTFS_XML_WRONG_BLOCKSIZE, "I5049E", EINVAL},
{ LTFS_XML_WRONG_COMP, "I5050E", EINVAL},
{ LTFS_BAD_INDEX_TYPE, "I5051E", EINVAL},
{ EDEV_NO_SENSE, "D0000E", EIO},
{ EDEV_OVERRUN, "D0002E", EIO},
{ EDEV_UNDERRUN, "D0003E", ENODATA},
Expand Down
Loading

0 comments on commit 8c8f6cc

Please sign in to comment.