Package com.ceph.fs
Class CephMount
- java.lang.Object
-
- com.ceph.fs.CephMount
-
public class CephMount extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description static int
LOCK_EX
static int
LOCK_NB
static int
LOCK_SH
static int
LOCK_UN
static int
O_APPEND
static int
O_CREAT
static int
O_DIRECTORY
static int
O_EXCL
static int
O_RDONLY
static int
O_RDWR
static int
O_TRUNC
static int
O_WRONLY
static int
SEEK_CUR
static int
SEEK_END
static int
SEEK_SET
static int
SETATTR_ATIME
static int
SETATTR_GID
static int
SETATTR_MODE
static int
SETATTR_MTIME
static int
SETATTR_UID
static int
XATTR_CREATE
static int
XATTR_NONE
static int
XATTR_REPLACE
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
chdir(java.lang.String path)
Set the current working directory.void
chmod(java.lang.String path, int mode)
Change file mode.void
close(int fd)
Close an open file.java.lang.String
conf_get(java.lang.String option)
Get the value of a configuration option.void
conf_read_file(java.lang.String path)
Load configuration from a file.void
conf_set(java.lang.String option, java.lang.String value)
Set the value of a configuration option.void
fchmod(int fd, int mode)
Change file mode of an open file.protected void
finalize()
void
flock(int fd, int operation, long owner)
Apply or remove an advisory lock.void
fstat(int fd, CephStat stat)
Get file status.void
fsync(int fd, boolean dataonly)
Synchronize a file with the file system.void
ftruncate(int fd, long size)
Truncate a file.java.lang.String
get_default_data_pool_name()
Get the default data pool of cephfs.CephFileExtent
get_file_extent(int fd, long offset)
Get file extent containing a given offset.java.lang.String
get_file_pool_name(int fd)
Get the name of the pool a file is stored in.int
get_file_replication(int fd)
Get the replication of a file.int
get_file_stripe_unit(int fd)
Get the stripe unit of a file.java.net.InetAddress
get_osd_address(int osd)
Get the network address of an OSD.Bucket[]
get_osd_crush_location(int osd)
Get the fully qualified CRUSH location of an OSD.int
get_pool_id(java.lang.String name)
Get the pool id for the named pool.int
get_pool_replication(int pool_id)
Get the pool replication factor.int
get_stripe_unit_granularity()
Get file layout stripe unit granularity.java.lang.String
getcwd()
Get the current working directory.long
getxattr(java.lang.String path, java.lang.String name, byte[] buf)
Get an extended attribute value.long
lgetxattr(java.lang.String path, java.lang.String name, byte[] buf)
Get an extended attribute value of a symbolic link.void
link(java.lang.String oldpath, java.lang.String newpath)
Create a hard link to an existing file.java.lang.String[]
listdir(java.lang.String dir)
List the contents of a directory.java.lang.String[]
listxattr(java.lang.String path)
List extended attributes.java.lang.String[]
llistxattr(java.lang.String path)
List extended attributes of a symbolic link.void
localize_reads(boolean state)
Favor reading from local replicas when possible.void
lremovexattr(java.lang.String path, java.lang.String name)
Remove an extended attribute from a symbolic link.long
lseek(int fd, long offset, int whence)
Seek to a position in a file.void
lsetxattr(java.lang.String path, java.lang.String name, byte[] buf, long size, int flags)
Set the value of an extended attribute on a symbolic link.void
lstat(java.lang.String path, CephStat stat)
Get file status, without following symlinks.void
mkdir(java.lang.String path, int mode)
Create a directory.void
mkdirs(java.lang.String path, int mode)
Create a directory and all parents.void
mount(java.lang.String root)
Activate the mount with a given root path.int
open(java.lang.String path, int flags, int mode)
Open a file.int
open(java.lang.String path, int flags, int mode, int stripe_unit, int stripe_count, int object_size, java.lang.String data_pool)
Open a file with a specific file layout.long
read(int fd, byte[] buf, long size, long offset)
Read from a file.java.lang.String
readlink(java.lang.String path)
Read the value of a symbolic link.void
removexattr(java.lang.String path, java.lang.String name)
Remove an extended attribute.void
rename(java.lang.String from, java.lang.String to)
Rename a file or directory.void
rmdir(java.lang.String path)
Delete a directory.void
setattr(java.lang.String path, CephStat stat, int mask)
Set file attributes.void
setxattr(java.lang.String path, java.lang.String name, byte[] buf, long size, int flags)
Set the value of an extended attribute.void
stat(java.lang.String path, CephStat stat)
Get file status.void
statfs(java.lang.String path, CephStatVFS statvfs)
Get file system status.void
symlink(java.lang.String oldpath, java.lang.String newpath)
Create a symbolic link.void
sync_fs()
Synchronize the client with the file system.void
truncate(java.lang.String path, long size)
Truncate a file to a specified length.void
unlink(java.lang.String path)
Unlink/delete a name from the file system.void
unmount()
Deactivate the mount.long
write(int fd, byte[] buf, long size, long offset)
Write to a file at a specific offset.
-
-
-
Field Detail
-
O_RDONLY
public static final int O_RDONLY
- See Also:
- Constant Field Values
-
O_RDWR
public static final int O_RDWR
- See Also:
- Constant Field Values
-
O_APPEND
public static final int O_APPEND
- See Also:
- Constant Field Values
-
O_CREAT
public static final int O_CREAT
- See Also:
- Constant Field Values
-
O_TRUNC
public static final int O_TRUNC
- See Also:
- Constant Field Values
-
O_EXCL
public static final int O_EXCL
- See Also:
- Constant Field Values
-
O_WRONLY
public static final int O_WRONLY
- See Also:
- Constant Field Values
-
O_DIRECTORY
public static final int O_DIRECTORY
- See Also:
- Constant Field Values
-
SEEK_SET
public static final int SEEK_SET
- See Also:
- Constant Field Values
-
SEEK_CUR
public static final int SEEK_CUR
- See Also:
- Constant Field Values
-
SEEK_END
public static final int SEEK_END
- See Also:
- Constant Field Values
-
SETATTR_MODE
public static final int SETATTR_MODE
- See Also:
- Constant Field Values
-
SETATTR_UID
public static final int SETATTR_UID
- See Also:
- Constant Field Values
-
SETATTR_GID
public static final int SETATTR_GID
- See Also:
- Constant Field Values
-
SETATTR_MTIME
public static final int SETATTR_MTIME
- See Also:
- Constant Field Values
-
SETATTR_ATIME
public static final int SETATTR_ATIME
- See Also:
- Constant Field Values
-
XATTR_CREATE
public static final int XATTR_CREATE
- See Also:
- Constant Field Values
-
XATTR_REPLACE
public static final int XATTR_REPLACE
- See Also:
- Constant Field Values
-
XATTR_NONE
public static final int XATTR_NONE
- See Also:
- Constant Field Values
-
LOCK_SH
public static final int LOCK_SH
- See Also:
- Constant Field Values
-
LOCK_EX
public static final int LOCK_EX
- See Also:
- Constant Field Values
-
LOCK_NB
public static final int LOCK_NB
- See Also:
- Constant Field Values
-
LOCK_UN
public static final int LOCK_UN
- See Also:
- Constant Field Values
-
-
Method Detail
-
finalize
protected void finalize() throws java.lang.Throwable
- Overrides:
finalize
in classjava.lang.Object
- Throws:
java.lang.Throwable
-
mount
public void mount(java.lang.String root)
Activate the mount with a given root path.- Parameters:
root
- The path to use as the root (pass null for "/").
-
unmount
public void unmount()
Deactivate the mount. The mount can be reactivated using mount(). Configuration parameters previously set are not reset.
-
conf_read_file
public void conf_read_file(java.lang.String path) throws java.io.FileNotFoundException
Load configuration from a file.- Parameters:
path
- The path to the configuration file.- Throws:
java.io.FileNotFoundException
-
conf_set
public void conf_set(java.lang.String option, java.lang.String value)
Set the value of a configuration option.- Parameters:
option
- The configuration option to modify.value
- The new value of the option.
-
conf_get
public java.lang.String conf_get(java.lang.String option)
Get the value of a configuration option.- Parameters:
option
- The name of the configuration option.- Returns:
- The value of the option or null if option not found
-
statfs
public void statfs(java.lang.String path, CephStatVFS statvfs) throws java.io.FileNotFoundException
Get file system status.- Parameters:
path
- Path to file in file system.statvfs
- CephStatVFS structure to hold status.- Throws:
java.io.FileNotFoundException
-
getcwd
public java.lang.String getcwd()
Get the current working directory.- Returns:
- The current working directory in Ceph.
-
chdir
public void chdir(java.lang.String path) throws java.io.FileNotFoundException
Set the current working directory.- Parameters:
path
- The directory set as the cwd.- Throws:
java.io.FileNotFoundException
-
listdir
public java.lang.String[] listdir(java.lang.String dir) throws java.io.FileNotFoundException
List the contents of a directory.- Parameters:
dir
- The directory.- Returns:
- List of files and directories excluding "." and "..".
- Throws:
java.io.FileNotFoundException
-
link
public void link(java.lang.String oldpath, java.lang.String newpath) throws java.io.FileNotFoundException
Create a hard link to an existing file.- Parameters:
oldpath
- The target path of the link.newpath
- The name of the link.- Throws:
java.io.FileNotFoundException
-
unlink
public void unlink(java.lang.String path) throws java.io.FileNotFoundException
Unlink/delete a name from the file system.- Parameters:
path
- The name to unlink/delete.- Throws:
java.io.FileNotFoundException
-
rename
public void rename(java.lang.String from, java.lang.String to) throws java.io.FileNotFoundException
Rename a file or directory.- Parameters:
from
- The current path.to
- The new path.- Throws:
java.io.FileNotFoundException
-
mkdir
public void mkdir(java.lang.String path, int mode)
Create a directory.- Parameters:
path
- The directory to create.mode
- The mode of the new directory.
-
mkdirs
public void mkdirs(java.lang.String path, int mode) throws java.io.IOException
Create a directory and all parents.- Parameters:
path
- The directory to create.mode
- The mode of the new directory.- Throws:
java.io.IOException
-
rmdir
public void rmdir(java.lang.String path) throws java.io.FileNotFoundException
Delete a directory.- Parameters:
path
- The directory to delete.- Throws:
java.io.FileNotFoundException
-
readlink
public java.lang.String readlink(java.lang.String path) throws java.io.FileNotFoundException
Read the value of a symbolic link.- Throws:
java.io.FileNotFoundException
-
symlink
public void symlink(java.lang.String oldpath, java.lang.String newpath)
Create a symbolic link.- Parameters:
oldpath
- Target of the symbolic link.newpath
- Name of the link.
-
stat
public void stat(java.lang.String path, CephStat stat) throws java.io.FileNotFoundException, CephNotDirectoryException
Get file status.- Parameters:
path
- Path of file to stat.stat
- CephStat structure to hold file status.- Throws:
java.io.FileNotFoundException
CephNotDirectoryException
-
lstat
public void lstat(java.lang.String path, CephStat stat) throws java.io.FileNotFoundException, CephNotDirectoryException
Get file status, without following symlinks.- Parameters:
path
- Path of file to stat.stat
- CephStat structure to hold file status.- Throws:
java.io.FileNotFoundException
CephNotDirectoryException
-
setattr
public void setattr(java.lang.String path, CephStat stat, int mask) throws java.io.FileNotFoundException
Set file attributes.- Parameters:
path
- Path to file.stat
- CephStat structure holding attributes.mask
- Mask specifying which attributes to set.- Throws:
java.io.FileNotFoundException
-
chmod
public void chmod(java.lang.String path, int mode) throws java.io.FileNotFoundException
Change file mode.- Parameters:
path
- Path to file.mode
- New mode bits.- Throws:
java.io.FileNotFoundException
-
fchmod
public void fchmod(int fd, int mode)
Change file mode of an open file.- Parameters:
fd
- The open file descriptor to change the mode bits on.mode
- New mode bits.
-
truncate
public void truncate(java.lang.String path, long size) throws java.io.FileNotFoundException
Truncate a file to a specified length.- Parameters:
path
- Path of the file.size
- New file length.- Throws:
java.io.FileNotFoundException
-
open
public int open(java.lang.String path, int flags, int mode) throws java.io.FileNotFoundException
Open a file.- Parameters:
path
- Path of file to open or create.flags
- Open flags.mode
- Permission mode.- Returns:
- File descriptor.
- Throws:
java.io.FileNotFoundException
-
open
public int open(java.lang.String path, int flags, int mode, int stripe_unit, int stripe_count, int object_size, java.lang.String data_pool) throws java.io.FileNotFoundException
Open a file with a specific file layout.- Parameters:
path
- Path of file to open or create.flags
- Open flags.mode
- Permission mode.stripe_unit
- File layout stripe unit size.stripe_count
- File layout stripe count.object_size
- Size of each object.data_pool
- The target data pool.- Returns:
- File descriptor.
- Throws:
java.io.FileNotFoundException
-
close
public void close(int fd)
Close an open file.- Parameters:
fd
- The file descriptor.
-
lseek
public long lseek(int fd, long offset, int whence)
Seek to a position in a file.- Parameters:
fd
- File descriptor.offset
- New offset.whence
- Whence value.- Returns:
- The new offset.
-
read
public long read(int fd, byte[] buf, long size, long offset)
Read from a file.- Parameters:
fd
- The file descriptor.buf
- Buffer to for data read.size
- Amount of data to read into the buffer.offset
- Offset to read from (-1 for current position).- Returns:
- The number of bytes read.
-
write
public long write(int fd, byte[] buf, long size, long offset)
Write to a file at a specific offset.- Parameters:
fd
- The file descriptor.buf
- Buffer to write.size
- Amount of data to write.offset
- Offset to write from (-1 for current position).- Returns:
- The number of bytes written.
-
ftruncate
public void ftruncate(int fd, long size)
Truncate a file.- Parameters:
fd
- File descriptor of the file to truncate.size
- New file size.
-
fsync
public void fsync(int fd, boolean dataonly)
Synchronize a file with the file system.- Parameters:
fd
- File descriptor to synchronize.dataonly
- Synchronize only data.
-
flock
public void flock(int fd, int operation, long owner) throws java.io.IOException
Apply or remove an advisory lock.- Parameters:
fd
- File descriptor to lock or unlock.operation
- the advisory lock operation to be performed on the file descriptor among LOCK_SH (shared lock), LOCK_EX (exclusive lock), or LOCK_UN (remove lock). The LOCK_NB value can be ORed to perform a non-blocking operation.owner
- the user-supplied owner identifier (an arbitrary integer)- Throws:
java.io.IOException
-
fstat
public void fstat(int fd, CephStat stat)
Get file status.- Parameters:
fd
- The file descriptor.stat
- The object in which to store the status.
-
sync_fs
public void sync_fs()
Synchronize the client with the file system.
-
getxattr
public long getxattr(java.lang.String path, java.lang.String name, byte[] buf) throws java.io.FileNotFoundException
Get an extended attribute value. If the buffer is large enough to hold the entire attribute value, or buf is null, the size of the value is returned.- Parameters:
path
- File path.name
- Name of the attribute.buf
- Buffer to store attribute value.- Returns:
- The length of the attribute value. See description for more details.
- Throws:
java.io.FileNotFoundException
-
lgetxattr
public long lgetxattr(java.lang.String path, java.lang.String name, byte[] buf) throws java.io.FileNotFoundException
Get an extended attribute value of a symbolic link. If the buffer is large enough to hold the entire attribute value, or buf is null, the size of the value is returned.- Parameters:
path
- File path.name
- Name of attribute.buf
- Buffer to store attribute value.- Returns:
- The length of the attribute value. See description for more details.
- Throws:
java.io.FileNotFoundException
-
listxattr
public java.lang.String[] listxattr(java.lang.String path) throws java.io.FileNotFoundException
List extended attributes.- Parameters:
path
- File path.- Returns:
- List of attribute names.
- Throws:
java.io.FileNotFoundException
-
llistxattr
public java.lang.String[] llistxattr(java.lang.String path) throws java.io.FileNotFoundException
List extended attributes of a symbolic link.- Parameters:
path
- File path.- Returns:
- List of attribute names.
- Throws:
java.io.FileNotFoundException
-
removexattr
public void removexattr(java.lang.String path, java.lang.String name) throws java.io.FileNotFoundException
Remove an extended attribute.- Parameters:
path
- File path.name
- Name of attribute.- Throws:
java.io.FileNotFoundException
-
lremovexattr
public void lremovexattr(java.lang.String path, java.lang.String name) throws java.io.FileNotFoundException
Remove an extended attribute from a symbolic link.- Parameters:
path
- File path.name
- Name of attribute.- Throws:
java.io.FileNotFoundException
-
setxattr
public void setxattr(java.lang.String path, java.lang.String name, byte[] buf, long size, int flags) throws java.io.FileNotFoundException
Set the value of an extended attribute.- Parameters:
path
- The file path.name
- The attribute name.buf
- The attribute value.size
- The size of the attribute value.flags
- Flag controlling behavior (XATTR_CREATE/REPLACE/NONE).- Throws:
java.io.FileNotFoundException
-
lsetxattr
public void lsetxattr(java.lang.String path, java.lang.String name, byte[] buf, long size, int flags) throws java.io.FileNotFoundException
Set the value of an extended attribute on a symbolic link.- Parameters:
path
- The file path.name
- The attribute name.buf
- The attribute value.size
- The size of the attribute value.flags
- Flag controlling behavior (XATTR_CREATE/REPLACE/NONE).- Throws:
java.io.FileNotFoundException
-
get_file_stripe_unit
public int get_file_stripe_unit(int fd)
Get the stripe unit of a file.- Parameters:
fd
- The file descriptor.- Returns:
- The stripe unit.
-
get_file_pool_name
public java.lang.String get_file_pool_name(int fd)
Get the name of the pool a file is stored in.- Parameters:
fd
- An open file descriptor.- Returns:
- The pool name.
-
get_default_data_pool_name
public java.lang.String get_default_data_pool_name()
Get the default data pool of cephfs.- Returns:
- The pool name.
-
get_file_replication
public int get_file_replication(int fd)
Get the replication of a file.- Parameters:
fd
- The file descriptor.- Returns:
- The file replication.
-
localize_reads
public void localize_reads(boolean state)
Favor reading from local replicas when possible.- Parameters:
state
- Enable or disable localized reads.
-
get_stripe_unit_granularity
public int get_stripe_unit_granularity()
Get file layout stripe unit granularity.- Returns:
- Stripe unit granularity.
-
get_pool_id
public int get_pool_id(java.lang.String name) throws CephPoolException
Get the pool id for the named pool.- Parameters:
name
- The pool name.- Returns:
- The pool id.
- Throws:
CephPoolException
-
get_pool_replication
public int get_pool_replication(int pool_id) throws CephPoolException
Get the pool replication factor.- Parameters:
pool_id
- The pool id.- Returns:
- Number of replicas stored in the pool.
- Throws:
CephPoolException
-
get_file_extent
public CephFileExtent get_file_extent(int fd, long offset)
Get file extent containing a given offset.- Parameters:
fd
- The file descriptor.offset
- Offset in file.- Returns:
- A CephFileExtent object.
-
get_osd_crush_location
public Bucket[] get_osd_crush_location(int osd)
Get the fully qualified CRUSH location of an OSD. Returns (type, name) string pairs for each device in the CRUSH bucket hierarchy starting from the given OSD to the root.- Parameters:
osd
- The OSD device id.- Returns:
- List of pairs.
-
get_osd_address
public java.net.InetAddress get_osd_address(int osd)
Get the network address of an OSD.- Parameters:
osd
- The OSD device id.- Returns:
- The network address.
-
-