Utilities

The utils modules provides convenience methods built for the GPFS C API.

utils provides more complex functionality than CLib’s other classes which are a thin wrapper over the functions available in the GPFS C API.

Note

Most methods require root permission

Description

Miscellaneous Functions

Filesystem Snapshot Identifier Convenience Functions

Directory Scan Convenience Functions

Inode Scan Convenience Functions

Examples

Walk the filesystem

>>> import os
>>> from arcapix.fs.gpfs.clib.utils import walk
>>>
>>> for root, dirs, files in walk("/mmfs1"):
...     for name in files:
...         print(os.path.join(root, name))
...     for name in dirs:
...         print(os.path.join(root, name))
/mmfs1/test
/mmfs1/data
/mmfs1/.policytmp

Get the filesystem a given path belongs to

>>> from arcapix.fs.gpfs import Filesystem
>>> from arcapix.fs.gpfs.clib.utils import get_fsname_by_path
>>>
>>> fs = Filesystem(get_fsname_by_path('/mmfs1/data'))
>>>
>>> print fs.name
'mmfs1'

Walk the filesystem for a given snapshot

>>> import os
>>> from arcapix.fs.gpfs.clib.utils import scandir
>>>
>>> def walk(root, snap):
...     for i in scandir(root, snap):
...         yield i.path
...         # recurse into the directory
...         if i.is_dir():
...             for d in walk(i.path, snap):
...                 yield d
...
>>> for i in walk('/mmfs1', 'snap1'):
...     print i
...
/mmfs1/.snapshots/snap1/data
/mmfs1/.snapshots/snap1/.policytmp

Calculate the total size of temporary files on the filesystem

>>> import os
>>> from arcapix.fs.gpfs.clib.utils import scandir, inode_iterator
>>>
>>> # iterator of inode numbers for files that end '.tmp'
>>> def find_inodes(root):
...     for i in scandir(root):
...         if i.name.endswith('.tmp'):
...             yield i.inode()
...         # recurse into the directory
...         if i.is_dir():
...             for d in find_inodes(i.path):
...                 yield d
...
>>> # list of inode number of '.tmp' files
>>> inodes = list(find_inodes('/mmfs1'))
>>>
>>> # create iterator - use max and min to limit scope of scan
>>> itr = inode_iterator('mmfs1', fromInode=min(inode), toInode=max(inodes)+1)
>>>
>>> # add up sizes of inodes in the inode list
>>> print sum(x.ia_size for x in itr if x.ia_inode in inodes)
100421