Skip to content

Commit

Permalink
Support limit of name length by Alluxio FUSE Alluxio#9415
Browse files Browse the repository at this point in the history
Signed-off-by: hongtongliu <[email protected]>

Fix Alluxio#9415

pr-link: Alluxio#9419
change-id: cid-f183fb2164b691143ff0ecec075f60ec218df0a8
  • Loading branch information
liuhongtong authored and alluxio-bot committed Jul 10, 2019
1 parent 1ae5d12 commit 1155b10
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ public final class AlluxioFuseFileSystem extends FuseStubFS {
private static final Logger LOG = LoggerFactory.getLogger(AlluxioFuseFileSystem.class);
private static final int MAX_OPEN_FILES = Integer.MAX_VALUE;
private static final int MAX_OPEN_WAITTIME_MS = 5000;
/**
* Most FileSystems on linux limit the length of file name beyond 255 characters.
*/
private static final int MAX_NAME_LENGTH = 255;

/**
* 4294967295 is unsigned long -1, -1 means that uid or gid is not set.
Expand Down Expand Up @@ -242,6 +246,11 @@ public int create(String path, @mode_t long mode, FuseFileInfo fi) {
final int flags = fi.flags.get();
LOG.trace("create({}, {}) [Alluxio: {}]", path, Integer.toHexString(flags), uri);

if (uri.getName().length() > MAX_NAME_LENGTH) {
LOG.error("Failed to create {}, file name is longer than {} characters",
path, MAX_NAME_LENGTH);
return -ErrorCodes.ENAMETOOLONG();
}
try {
if (mOpenFiles.size() >= MAX_OPEN_FILES) {
LOG.error("Cannot create {}: too many open files (MAX_OPEN_FILES: {})", path,
Expand Down Expand Up @@ -393,7 +402,13 @@ public String getFSName() {
@Override
public int mkdir(String path, @mode_t long mode) {
final AlluxioURI turi = mPathResolverCache.getUnchecked(path);
final String name = turi.getName();
LOG.trace("mkdir({}) [Alluxio: {}]", path, turi);
if (turi.getName().length() > MAX_NAME_LENGTH) {
LOG.error("Failed to create directory {}, directory name is longer than {} characters",
path, MAX_NAME_LENGTH);
return -ErrorCodes.ENAMETOOLONG();
}
try {
mFileSystem.createDirectory(turi,
CreateDirectoryPOptions.newBuilder()
Expand Down Expand Up @@ -603,8 +618,14 @@ public int release(String path, FuseFileInfo fi) {
public int rename(String oldPath, String newPath) {
final AlluxioURI oldUri = mPathResolverCache.getUnchecked(oldPath);
final AlluxioURI newUri = mPathResolverCache.getUnchecked(newPath);
final String name = newUri.getName();
LOG.trace("rename({}, {}) [Alluxio: {}, {}]", oldPath, newPath, oldUri, newUri);

if (name.length() > MAX_NAME_LENGTH) {
LOG.error("Failed to rename {} to {}, name {} is longer than {} characters",
oldPath, newPath, name, MAX_NAME_LENGTH);
return -ErrorCodes.ENAMETOOLONG();
}
try {
mFileSystem.rename(oldUri, newUri);
synchronized (mOpenFiles) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,14 @@ public void create() throws Exception {
.build());
}

@Test
public void createWithLengthLimit() throws Exception {
String c256 = String.join("", Collections.nCopies(16, "0123456789ABCDEF"));
mFileInfo.flags.set(O_WRONLY.intValue());
assertEquals(-ErrorCodes.ENAMETOOLONG(),
mFuseFs.create("/foo/" + c256, 0, mFileInfo));
}

@Test
public void flush() throws Exception {
FileOutStream fos = mock(FileOutStream.class);
Expand Down Expand Up @@ -314,6 +322,14 @@ public void mkDir() throws Exception {
.build());
}

@Test
public void mkDirWithLengthLimit() throws Exception {
long mode = 0755L;
String c256 = String.join("", Collections.nCopies(16, "0123456789ABCDEF"));
assertEquals(-ErrorCodes.ENAMETOOLONG(),
mFuseFs.mkdir("/foo/" + c256, mode));
}

@Test
public void openWithoutDelay() throws Exception {
AlluxioURI expectedPath = BASE_EXPECTED_URI.join("/foo/bar");
Expand Down Expand Up @@ -416,6 +432,16 @@ public void renameNewExist() throws Exception {
assertEquals(-ErrorCodes.EEXIST(), mFuseFs.rename("/old", "/new"));
}

@Test
public void renameWithLengthLimit() throws Exception {
String c256 = String.join("", Collections.nCopies(16, "0123456789ABCDEF"));
AlluxioURI oldPath = BASE_EXPECTED_URI.join("/old");
AlluxioURI newPath = BASE_EXPECTED_URI.join("/" + c256);
doNothing().when(mFileSystem).rename(oldPath, newPath);
assertEquals(-ErrorCodes.ENAMETOOLONG(),
mFuseFs.rename("/old", "/" + c256));
}

@Test
public void rmdir() throws Exception {
AlluxioURI expectedPath = BASE_EXPECTED_URI.join("/foo/bar");
Expand Down

0 comments on commit 1155b10

Please sign in to comment.