diff options
author | Robin Appelman <robin@icewind.nl> | 2017-02-13 15:03:46 +0100 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2017-02-13 15:03:46 +0100 |
commit | 8c1ed7507aae772fdc274e98bb2fa31d9d3f8f99 (patch) | |
tree | 6d09ce07007cc40713cc4b4babe9765bf10d945a /lib | |
parent | 88047aaea732d77bf38730566842fc163c6ba3a1 (diff) | |
download | nextcloud-server-8c1ed7507aae772fdc274e98bb2fa31d9d3f8f99.tar.gz nextcloud-server-8c1ed7507aae772fdc274e98bb2fa31d9d3f8f99.zip |
Add option to enable locking debug logging
Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Files/Storage/Common.php | 51 |
1 files changed, 48 insertions, 3 deletions
diff --git a/lib/private/Files/Storage/Common.php b/lib/private/Files/Storage/Common.php index f3e3cb9e58c..f0d0faac2c0 100644 --- a/lib/private/Files/Storage/Common.php +++ b/lib/private/Files/Storage/Common.php @@ -53,6 +53,7 @@ use OCP\Files\InvalidPathException; use OCP\Files\ReservedWordException; use OCP\Files\Storage\ILockingStorage; use OCP\Lock\ILockingProvider; +use OCP\Lock\LockedException; /** * Storage backend class for providing common filesystem operation methods @@ -79,6 +80,9 @@ abstract class Common implements Storage, ILockingStorage { protected $mountOptions = []; protected $owner = null; + private $shouldLogLocks = null; + private $logger; + public function __construct($parameters) { } @@ -681,7 +685,18 @@ abstract class Common implements Storage, ILockingStorage { * @throws \OCP\Lock\LockedException */ public function acquireLock($path, $type, ILockingProvider $provider) { - $provider->acquireLock('files/' . md5($this->getId() . '::' . trim($path, '/')), $type); + $logger = $this->getLockLogger(); + if ($logger) { + $typeString = ($type === ILockingProvider::LOCK_SHARED) ? 'shared' : 'exclusive'; + $logger->info('acquire ' . $typeString . ' lock on ' . $path, ['app' => 'locking']); + } + try { + $provider->acquireLock('files/' . md5($this->getId() . '::' . trim($path, '/')), $type); + } catch (LockedException $e) { + if ($logger) { + $logger->logException($e); + } + } } /** @@ -690,7 +705,18 @@ abstract class Common implements Storage, ILockingStorage { * @param \OCP\Lock\ILockingProvider $provider */ public function releaseLock($path, $type, ILockingProvider $provider) { - $provider->releaseLock('files/' . md5($this->getId() . '::' . trim($path, '/')), $type); + $logger = $this->getLockLogger(); + if ($logger) { + $typeString = ($type === ILockingProvider::LOCK_SHARED) ? 'shared' : 'exclusive'; + $logger->info('release ' . $typeString . ' lock on ' . $path, ['app' => 'locking']); + } + try { + $provider->releaseLock('files/' . md5($this->getId() . '::' . trim($path, '/')), $type); + } catch (LockedException $e) { + if ($logger) { + $logger->logException($e); + } + } } /** @@ -699,7 +725,26 @@ abstract class Common implements Storage, ILockingStorage { * @param \OCP\Lock\ILockingProvider $provider */ public function changeLock($path, $type, ILockingProvider $provider) { - $provider->changeLock('files/' . md5($this->getId() . '::' . trim($path, '/')), $type); + $logger = $this->getLockLogger(); + if ($logger) { + $typeString = ($type === ILockingProvider::LOCK_SHARED) ? 'shared' : 'exclusive'; + $logger->info('change lock on ' . $path . ' to ' . $typeString, ['app' => 'locking']); + } + try { + $provider->changeLock('files/' . md5($this->getId() . '::' . trim($path, '/')), $type); + } catch (LockedException $e) { + if ($logger) { + $logger->logException($e); + } + } + } + + private function getLockLogger() { + if (is_null($this->shouldLogLocks)) { + $this->shouldLogLocks = \OC::$server->getConfig()->getSystemValue('filelocking.debug', false); + $this->logger = $this->shouldLogLocks ? \OC::$server->getLogger() : null; + } + return $this->logger; } /** |