Current File : //usr/libexec/lsm.d/find_unused_lun.pyo |
�
/�P`c @ s� d d l Z d d l Z d d l Z d d l Z d d l m Z m Z m Z m Z d � Z d � Z
d � Z d � Z d � Z
d � Z d � Z e d
k r� e � n d S( i����N( t Clientt LsmErrort ErrorNumbert LocalDiskc C s$ t j j | � t j j d � d S( Ns
( t syst stderrt write( t msg( ( s% /usr/libexec/lsm.d/find_unused_lun.pyt print_stderr s c C s� y* t j | t j � } t j | � t SWnS t k
r } | j t j k rR t S| j t j k ry t
t j d � � q� � n Xd S( s
The manpage of open(2):
There is one exception: on Linux 2.6 and later, O_EXCL can be used
without O_CREAT if pathname refers to a block device. If the block
device is in use by the system (e.g., mounted), open() fails with the
error EBUSY.
Even when disk has partitions, when all partitions are not used, this
function still treats it as free disk.
When specific disk or its partition is used by LVM, if there is no data
stored in it, this function still treats it as free disk.
s( Permission deny, try sudo or run as rootN(
t ost opent O_EXCLt closet Truet OSErrort errnot EBUSYt Falset EACCESR R t PERMISSION_DENIED( t blk_patht fdt err( ( s% /usr/libexec/lsm.d/find_unused_lun.pyt is_free_disk s
c C s� | t d � } d | } y t j | � } Wn t k
rA d SXt | � d k rX d S| d } d | } d | } t | � � } | j � j d � s� d SWd QXt | � � } | j � j � SWd QXd S( s�
Use `/sys/block/sdX/holders/dm-0/dm/name` to get mpath name,
use `/sys/block/sdf/holders/dm-0/dm/uuid` to check whether holder is
multipath.
s /dev/s /sys/block/%s/holdersi i s /sys/block/%s/dm/names /sys/block/%s/dm/uuids mpath-N( t lenR t listdirt FileNotFoundErrort NoneR
t readt
startswitht strip( R t blk_namet sysfs_holder_foldert holderst holder_namet sysfs_dm_name_patht sysfs_dm_uuid_patht f( ( s% /usr/libexec/lsm.d/find_unused_lun.pyt get_mpath: s
c C s$ t | � } | r t d | � St S( Ns /dev/mapper/%s( R&