rtslib/utils.py
def is_dev_in_use(path):
    '''
    This function will check if the device or file referenced by path is
    already mounted or used as a storage object backend.  It works by trying to
    open the path with O_EXCL flag, which will fail if someone else already
    did.  Note that the file is closed before the function returns, so this
    does not guaranteed the device will still be available after the check.
    @param path: path to the file of device to check
    @type path: string
    @return: A boolean, True is we cannot get exclusive descriptor on the path,
             False if we can.
    '''
    path = os.path.realpath(str(path))
    try:
        device = pyudev.Device.from_device_file(_CONTEXT, path)
        if device.subsystem == u'scsi_generic':
            file_fd = os.open(path, os.O_EXCL|os.O_NDELAY|os.O_RDWR)
        else:
            file_fd = os.open(path, os.O_EXCL|os.O_NDELAY)
    except OSError:
        return True
    else:
        os.close(file_fd)
        return False

    This function will check if the device or file referenced by path is
    already mounted or used as a storage object backend.  It works by trying to
    open the path with O_EXCL flag, which will fail if someone else already
    did.  Note that the file is closed before the function returns, so this
    does not guaranteed the device will still be available after the check.
    @param path: path to the file of device to check
    @type path: string
    @return: A boolean, True is we cannot get exclusive descriptor on the path,
             False if we can.
    
This function will check if the device or file referenced by path is
already mounted or used as a storage object backend.  It works by trying to
open the path with O_EXCL flag, which will fail if someone else already
did.  Note that the file is closed before the function returns, so this
does not guaranteed the device will still be available after the check.
This function will check if the device or file referenced by path is already mounted or used as a storage object backend . It works by trying to open the path with O_EXCL flag which will fail if someone else already did . Note that the file is closed before the function returns so this does not guaranteed the device will still be available after the check .
def is_dev_in_use(path):
    path = os.path.realpath(str(path))
    try:
        device = pyudev.Device.from_device_file(_CONTEXT, path)
        if device.subsystem == u'scsi_generic':
            file_fd = os.open(path, os.O_EXCL|os.O_NDELAY|os.O_RDWR)
        else:
            file_fd = os.open(path, os.O_EXCL|os.O_NDELAY)
    except OSError:
        return True
    else:
        os.close(file_fd)
        return False
def is_dev_in_use ( path ) : path = os . path . realpath ( str ( path ) ) try : device = pyudev . Device . from_device_file ( _CONTEXT , path ) if device . subsystem == u'scsi_generic' : file_fd = os . open ( path , os . O_EXCL | os . O_NDELAY | os . O_RDWR ) else : file_fd = os . open ( path , os . O_EXCL | os . O_NDELAY ) except OSError : return True else : os . close ( file_fd ) return False
This function will check if the device or file referenced by path is
already mounted or used as a storage object backend.
This function will check if the device or file referenced by path is already mounted or used as a storage object backend .
'''
    This function will check if the device or file referenced by path is
    already mounted or used as a storage object backend.  It works by trying to
    open the path with O_EXCL flag, which will fail if someone else already
    did.  Note that the file is closed before the function returns, so this
    does not guaranteed the device will still be available after the check.
    @param path: path to the file of device to check
    @type path: string
    @return: A boolean, True is we cannot get exclusive descriptor on the path,
             False if we can.
    '''
A boolean, True is we cannot get exclusive descriptor on the path,
False if we can.
A boolean True is we cannot get exclusive descriptor on the path False if we can .
path
path to the file of device to check
path to the file of device to check