Skip to content

Commit

Permalink
Do lock operations as root via xrootd
Browse files Browse the repository at this point in the history
  • Loading branch information
glpatcern committed Nov 30, 2021
1 parent 88d35ab commit 46aec7a
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/core/xrootiface.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,32 +265,32 @@ def rmxattr(endpoint, filepath, userid, key):
_xrootcmd(endpoint, 'attr', 'rm', userid, 'mgm.attr.key=user.' + key + '&mgm.path=' + _getfilepath(filepath, encodeamp=True))


def setlock(endpoint, filepath, userid, value):
def setlock(endpoint, filepath, _userid, value):
'''Set a lock as an xattr with the special option "c" (create-if-not-exists) on behalf of the given userid'''
try:
log.debug('msg="Invoked setlock" filepath="%s"' % filepath)
setxattr(endpoint, filepath, userid, LOCKKEY, str(value) + '&mgm.option=c')
setxattr(endpoint, filepath, '0:0', LOCKKEY, str(value) + '&mgm.option=c')
except IOError as e:
if EXCL_XATTR_MSG in str(e):
raise IOError('File exists and islock flag requested')


def getlock(endpoint, filepath, userid):
def getlock(endpoint, filepath, _userid):
'''Get the lock metadata as an xattr on behalf of the given userid'''
log.debug('msg="Invoked getlock" filepath="%s"' % filepath)
return getxattr(endpoint, filepath, userid, LOCKKEY)
return getxattr(endpoint, filepath, '0:0', LOCKKEY)


def refreshlock(endpoint, filepath, userid, value):
def refreshlock(endpoint, filepath, _userid, value):
'''Refresh the lock value as an xattr on behalf of the given userid'''
log.debug('msg="Invoked refreshlock" filepath="%s"' % filepath)
if getxattr(endpoint, filepath, userid, LOCKKEY):
setxattr(endpoint, filepath, userid, LOCKKEY, value) # non-atomic, but the lock was already held
if getxattr(endpoint, filepath, '0:0', LOCKKEY):
setxattr(endpoint, filepath, '0:0', LOCKKEY, value) # non-atomic, but the lock was already held
else:
raise IOError('File was not locked')


def unlock(endpoint, filepath, userid):
def unlock(endpoint, filepath, _userid):
'''Remove a lock as an xattr on behalf of the given userid'''
log.debug('msg="Invoked unlock" filepath="%s"' % filepath)
rmxattr(endpoint, filepath, userid, LOCKKEY)
Expand Down

0 comments on commit 46aec7a

Please sign in to comment.