Support for longnames for files/directories (Linux part)

This patch adds the ability for zfs to support file/dir name up to 1023
bytes. This number is chosen so we can support up to 255 4-byte
characters. This new feature is represented by the new feature flag
feature@longname.

A new dataset property "longname" is also introduced to toggle longname
support for each dataset individually. This property can be disabled,
even if it contains longname files. In such case, new file cannot be
created with longname but existing longname files can still be looked
up.

Note that, to my knowledge native Linux filesystems don't support name
longer than 255 bytes. So there might be programs not able to work with
longname.

Note that NFS server may needs to use exportfs_get_name to reconnect
dentries, and the buffer being passed is limit to NAME_MAX+1 (256). So
NFS may not work when longname is enabled.

Note, FreeBSD vfs layer imposes a limit of 255 name lengh, so even
though we add code to support it here, it won't actually work.

Reviewed-by: Tony Hutter <hutter2@llnl.gov>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Signed-off-by: Chunwei Chen <david.chen@nutanix.com>
Closes #15921
This commit is contained in:
Sanjeev Bagewadi
2021-06-18 08:55:01 +00:00
committed by Brian Behlendorf
parent 3cf2bfa570
commit 20232ecfaa
41 changed files with 1239 additions and 406 deletions
+6
View File
@@ -1605,6 +1605,11 @@ nobase_dist_datadir_zfs_tests_tests_SCRIPTS += \
functional/link_count/link_count_001.ksh \
functional/link_count/link_count_root_inode.ksh \
functional/link_count/setup.ksh \
functional/longname/cleanup.ksh \
functional/longname/longname_001_pos.ksh \
functional/longname/longname_002_pos.ksh \
functional/longname/longname_003_pos.ksh \
functional/longname/setup.ksh \
functional/log_spacemap/log_spacemap_import_logs.ksh \
functional/migration/cleanup.ksh \
functional/migration/migration_001_pos.ksh \
@@ -1938,6 +1943,7 @@ nobase_dist_datadir_zfs_tests_tests_SCRIPTS += \
functional/rsend/rsend_031_pos.ksh \
functional/rsend/send-c_embedded_blocks.ksh \
functional/rsend/send-c_incremental.ksh \
functional/rsend/send-c_longname.ksh \
functional/rsend/send-c_lz4_disabled.ksh \
functional/rsend/send-c_mixed_compression.ksh \
functional/rsend/send-c_props.ksh \
@@ -110,5 +110,6 @@ if is_linux || is_freebsd; then
"feature@vdev_zaps_v2"
"feature@raidz_expansion"
"feature@fast_dedup"
"feature@longname"
)
fi
+34
View File
@@ -0,0 +1,34 @@
#!/bin/ksh -p
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
#
# Copyright (c) 2021 by Nutanix. All rights reserved.
#
. $STF_SUITE/include/libtest.shlib
default_cleanup
@@ -0,0 +1,132 @@
#! /bin/ksh -p
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright (c) 2021 by Nutanix. All rights reserved.
#
. $STF_SUITE/include/libtest.shlib
#
# DESCRIPTION:
# Verify the support for long filenames.
#
# STRATEGY:
# 0. On a fresh dataset ensure property "longname" is enabled by default.
# 1. Disable the longname.
# 2. Try to create a filename whose length is > 256 bytes. This should fail.
# 3. Enable "longname" property on the dataset.
# 4. Try to create files and dirs whose names are > 256 bytes.
# 5. Ensure that "ls" is able to list the file.
# 6. Ensure stat(1) is able to stat the file/directory.
# 7. Try to rename the files and directories
# 8. Try to delete the files and directories
verify_runnable "global"
WORKDIR=$TESTDIR/workdir
MOVEDIR=$TESTDIR/movedir/level2/level3/level4/level5/level6
function cleanup
{
log_must rm -rf $WORKDIR
log_must rm -rf $TESTDIR/movedir
}
LONGNAME=$(printf 'a%.0s' {1..512})
LONGFNAME="file-$LONGNAME"
LONGDNAME="dir-$LONGNAME"
LONGPNAME="mypipe-$LONGNAME"
LONGCNAME="char_dev-$LONGNAME"
LONGLNAME="link-$LONGNAME"
LONGNAME_255=$(printf 'a%.0s' {1..255})
LONGNAME_1023=$(printf 'a%.0s' {1..1023})
log_assert "Check longname support for directories/files"
log_onexit cleanup
log_must mkdir $WORKDIR
log_must mkdir -p $MOVEDIR
# Disable longname support
log_must zfs set longname=off $TESTPOOL/$TESTFS
#Ensure a file of length 255bytes can be created
log_must touch $WORKDIR/$LONGNAME_255
#Where as file of length 256bytes should fail
log_mustnot touch $WORKDIR/${LONGNAME_255}b
# Try to create a file with long name with property "longname=off"
log_mustnot touch $WORKDIR/$LONGFNAME
log_mustnot mkdir $WORKDIR/$LONGDNAME
# Enable longname support
log_must zfs set longname=on $TESTPOOL/$TESTFS
# Retry the longname creates and that should succeed
log_must mkdir $WORKDIR/$LONGDNAME
log_must touch $WORKDIR/$LONGFNAME
# Should be able to create a file with name of 1023 chars
log_must touch $WORKDIR/$LONGNAME_1023
# And names longer that 1023 should fail
log_mustnot touch $WORKDIR/${LONGNAME_1023}b
# Ensure the longnamed dir/file can be listed.
name=$(ls $WORKDIR/$LONGFNAME)
if [[ "${name}" != "$WORKDIR/$LONGFNAME" ]]; then
log_fail "Unable to list: $WORKDIR/$LONGFNAME ret:$name"
fi
name=$(ls -d $WORKDIR/$LONGDNAME)
if [[ "${name}" != "$WORKDIR/$LONGDNAME" ]]; then
log_fail "Unable to list: $WORKDIR/$LONGDNAME ret:$name"
fi
# Ensure stat works
log_must stat $WORKDIR/$LONGFNAME
log_must stat $WORKDIR/$LONGDNAME
# Ensure softlinks can be created from a longname to
# another longnamed file.
log_must ln -s $WORKDIR/$LONGFNAME $WORKDIR/$LONGLNAME
# Ensure a longnamed pipe and character device file
# can be created
log_must mknod $WORKDIR/$LONGPNAME p
log_must mknod $WORKDIR/$LONGCNAME c 92 1
# Ensure we can rename the longname file
log_must mv $WORKDIR/$LONGFNAME $WORKDIR/file2
# Delete the long named dir/file
log_must rmdir $WORKDIR/$LONGDNAME
log_must rm $WORKDIR/file2
log_must rm $WORKDIR/$LONGPNAME
log_must rm $WORKDIR/$LONGCNAME
log_must rm $WORKDIR/$LONGLNAME
log_pass
@@ -0,0 +1,115 @@
#! /bin/ksh -p
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright (c) 2021 by Nutanix. All rights reserved.
#
. $STF_SUITE/include/libtest.shlib
#
# DESCRIPTION:
# Check if longname feature is disabled by default and can be enabled.
#
# STRATEGY:
# 1. Create a zpool with longname feature disabled
# 2. Attempt to enable 'longname' property should fail.
# 3. Attempt to create a longnamed (>255) file should fail.
# 4. Enable the feature@longname
# 5. Enable 'longname' property on the dataset.
# 6. Should be able to create long named files and directories.
# 7. Should be able to disable longname property.
# 8. This should disallow creating new longnamed file/dirs. But, should be
# able to access existing longnamed files/dirs.
verify_runnable "global"
function cleanup
{
log_must rm -rf $WORKDIR
poolexists $TESTPOOL && zpool destroy $TESTPOOL
}
log_assert "Check feature@longname and 'longname' dataset propery work correctly"
log_onexit cleanup
log_must zpool destroy $TESTPOOL
log_must zpool create -o feature@longname=disabled $TESTPOOL $DISKS
log_must zfs create $TESTPOOL/$TESTFS2
log_must zfs set mountpoint=$TESTDIR2 $TESTPOOL/$TESTFS2
log_mustnot zfs set longname=on $TESTPOOL/$TESTFS2
LONGNAME=$(printf 'a%.0s' {1..512})
LONGFNAME="file-$LONGNAME"
LONGDNAME="dir-$LONGNAME"
SHORTDNAME="dir-short"
SHORTFNAME="file-short"
WORKDIR=$TESTDIR2/workdir
log_must mkdir $WORKDIR
log_mustnot touch $WORKDIR/$LONGFNAME
log_mustnot mkdir $WORKDIR/$LONGDNAME
log_must zpool set feature@longname=enabled $TESTPOOL
log_must zfs set longname=on $TESTPOOL/$TESTFS2
log_must mkdir $WORKDIR/$LONGDNAME
log_must touch $WORKDIR/$LONGFNAME
# Ensure the above changes are synced out.
log_must zpool sync $TESTPOOL
# Ensure that the feature is activated once longnamed files are created.
state=$(zpool get feature@longname -H -o value $TESTPOOL)
log_note "feature@longname on pool: $TESTPOOL : $state"
if [[ "$state" != "active" ]]; then
log_fail "feature@longname has state $state (expected active)"
fi
# Set longname=off.
log_must zfs set longname=off $TESTPOOL/$TESTFS2
# Ensure no new file/directory with longnames can be created or can be renamed
# to.
log_mustnot mkdir $WORKDIR/${LONGDNAME}.1
log_mustnot touch $WORKDIR/${LONGFNAME}.1
log_must mkdir $WORKDIR/$SHORTDNAME
log_mustnot mv $WORKDIR/$SHORTDNAME $WORKDIR/${LONGDNAME}.1
log_must touch $WORKDIR/$SHORTFNAME
log_mustnot mv $WORKDIR/$SHORTFNAME $WORKDIR/${LONGFNAME}.1
#Cleanup shortnames
log_must rmdir $WORKDIR/$SHORTDNAME
log_must rm $WORKDIR/$SHORTFNAME
# But, should be able to stat and rename existing files
log_must stat $WORKDIR/$LONGDNAME
log_must stat $WORKDIR/$LONGFNAME
log_must mv $WORKDIR/$LONGDNAME $WORKDIR/$SHORTDNAME
log_must mv $WORKDIR/$LONGFNAME $WORKDIR/$SHORTFNAME
log_pass
@@ -0,0 +1,113 @@
#! /bin/ksh -p
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright (c) 2021 by Nutanix. All rights reserved.
#
. $STF_SUITE/include/libtest.shlib
#
# DESCRIPTION:
# Check if longnames are handled correctly by ZIL replay and feature is activated.
#
# STRATEGY:
# 1. Create a zpool with longname feature disabled
# 2. Enable the feature@longname
# 3. Enable 'longname' property on the dataset.
# 4. Freeze the zpool
# 5. Create a longname
# 6. Export and import the zpool.
# 7. Replaying of longname create should activate the feature@longname
verify_runnable "global"
function cleanup
{
log_must rm -rf $WORKDIR
poolexists $TESTPOOL && zpool destroy $TESTPOOL
}
log_assert "Check feature@longname and 'longname' dataset propery work correctly"
log_onexit cleanup
poolexists $TESTPOOL && zpool destroy $TESTPOOL
log_must zpool create -o feature@longname=disabled $TESTPOOL $DISKS
log_must zfs create $TESTPOOL/$TESTFS
log_must zfs set mountpoint=$TESTDIR $TESTPOOL/$TESTFS
LONGNAME=$(printf 'a%.0s' {1..512})
LONGFNAME="file-$LONGNAME"
LONGDNAME="dir-$LONGNAME"
SHORTDNAME="dir-short"
SHORTFNAME="file-short"
WORKDIR=$TESTDIR/workdir
log_must mkdir $WORKDIR
log_must zpool set feature@longname=enabled $TESTPOOL
log_must zfs set longname=on $TESTPOOL/$TESTFS
# Ensure that the feature is NOT activated yet as no longnamed file is created.
state=$(zpool get feature@longname -H -o value $TESTPOOL)
log_note "feature@longname on pool: $TESTPOOL : $state"
if [[ "$state" != "enabled" ]]; then
log_fail "feature@longname has state $state (expected enabled)"
fi
#
# This dd command works around an issue where ZIL records aren't created
# after freezing the pool unless a ZIL header already exists. Create a file
# synchronously to force ZFS to write one out.
#
log_must dd if=/dev/zero of=/$WORKDIR/sync conv=fdatasync,fsync bs=1 count=1
log_must zpool freeze $TESTPOOL
log_must mkdir $WORKDIR/$LONGDNAME
log_must touch $WORKDIR/$LONGFNAME
# Export and re-import the zpool
log_must zpool export $TESTPOOL
log_must zpool import $TESTPOOL
# Ensure that the feature is activated once longnamed files are created.
state=$(zpool get feature@longname -H -o value $TESTPOOL)
log_note "feature@longname on pool: $TESTPOOL : $state"
if [[ "$state" != "active" ]]; then
log_fail "feature@longname has state $state (expected active)"
fi
# Destroying the dataset where the feature is activated should put the feature
# back to 'enabled' state
log_must zfs destroy -r $TESTPOOL/$TESTFS
state=$(zpool get feature@longname -H -o value $TESTPOOL)
log_note "feature@longname on pool: $TESTPOOL : $state"
if [[ "$state" != "enabled" ]]; then
log_fail "feature@longname has state $state (expected active)"
fi
log_pass
+35
View File
@@ -0,0 +1,35 @@
#!/bin/ksh -p
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2007 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
#
# Copyright (c) 2021 by Nutanix. All rights reserved.
#
. $STF_SUITE/include/libtest.shlib
DISK=${DISKS%% *}
default_setup $DISK
@@ -713,6 +713,7 @@ function stream_has_features
feature[resuming]="100000"
feature[redacted]="200000"
feature[compressed]="400000"
feature[longname]="10000000"
typeset flag known derived=0
for flag in "$@"; do
+98
View File
@@ -0,0 +1,98 @@
#!/bin/ksh -p
#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source. A copy of the CDDL is also available via the Internet at
# http://www.illumos.org/license/CDDL.
#
#
# Copyright (c) 2021 by Nutanix. All rights reserved.
#
. $STF_SUITE/tests/functional/rsend/rsend.kshlib
. $STF_SUITE/include/properties.shlib
#
# Description:
# Verify that longname featureflag is present in the stream.
#
# Strategy:
# 1. Create a filesystem with longnamed files/directories.
# 2. Verify that the sendstream has the longname featureflag is present in the
# send stream.
# 3. Verify the created streams can be received correctly.
# 4. Verify that the longnamed files/directories are present in the received
# filesystem.
#
verify_runnable "both"
log_assert "Verify that longnames are handled correctly in send stream."
log_onexit cleanup_pool $POOL $POOL2 $POOL3
typeset sendfs=$POOL/sendfs
typeset recvfs=$POOL2/recvfs
typeset recvfs3=$POOL3/recvfs
typeset stream=$BACKDIR/stream
typeset dump=$BACKDIR/dump
log_must zfs create -o longname=on $sendfs
typeset dir=$(get_prop mountpoint $sendfs)
# Create a longnamed dir and a file in the send dataset
LONGNAME=$(printf 'a%.0s' {1..512})
LONGFNAME="file-$LONGNAME"
LONGDNAME="dir-$LONGNAME"
log_must mkdir $dir/$LONGDNAME
log_must touch $dir/$LONGFNAME
# When POOL3 is created by rsend.kshlib feature@longname is 'enabled'.
# Recreate the POOL3 with feature@longname disabled.
datasetexists $POOL3 && log_must zpool destroy $POOL3
log_must zpool create -o feature@longname=disabled $POOL3 $DISK3
# Generate the streams and zstreamdump output.
log_must zfs snapshot $sendfs@now
log_must eval "zfs send -p $sendfs@now >$stream"
log_must eval "zstream dump -v <$stream >$dump"
log_must eval "zfs recv $recvfs <$stream"
cmp_ds_cont $sendfs $recvfs
log_must stream_has_features $stream longname
# Ensure the the receiving pool has feature@longname activated after receiving.
feat_val=$(zpool get -H -o value feature@longname $POOL2)
log_note "Zpool $POOL2 feature@longname=$feat_val"
if [[ "$feat_val" != "active" ]]; then
log_fail "pool $POOL2 feature@longname=$feat_val (expected 'active')"
fi
# Receiving of the stream on $POOL3 should fail as longname is not enabled
log_mustnot eval "zfs recv $recvfs3 <$stream"
# Enable feature@longname and retry the receiving the stream.
# It should succeed this time.
log_must eval "zpool set feature@longname=enabled $POOL3"
log_must eval "zfs recv $recvfs3 <$stream"
log_must zfs get longname $recvfs3
prop_val=$(zfs get -H -o value longname $recvfs3)
log_note "dataset $recvfs3 has longname=$prop_val"
if [[ "$prop_val" != "on" ]]; then
log_fail "$recvfs3 has longname=$prop_val (expected 'on')"
fi
#
# TODO:
# - Add a testcase to cover the case where send-stream does not contain
# properties (generated without "-p").
# In this case the target dataset would have longname files/directories which
# cannot be accessed if the dataset property 'longname=off'.
#
log_pass "Longnames are handled correctly in send/recv"