Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

dlm: avoid unnecessary posix unlock

When the kernel clears flocks/plocks during close, it calls posix
unlock when there are flocks but no posix locks. Without this
patch, that unnecessary posix unlock is passed to userland
(dlm_controld), across the cluster, and back to the kernel.
This can create a lot of plock activity, even when no posix
locks had been used.

This patch copies the nfs approach, and skips the full posix
unlock if there is no plock found during the vfs unlock phase.

Signed-off-by: David Teigland <teigland@redhat.com>

+15 -3
+15 -3
fs/dlm/plock.c
··· 247 247 struct dlm_ls *ls; 248 248 struct plock_op *op; 249 249 int rv; 250 + unsigned char fl_flags = fl->fl_flags; 250 251 251 252 ls = dlm_find_lockspace_local(lockspace); 252 253 if (!ls) ··· 259 258 goto out; 260 259 } 261 260 262 - if (posix_lock_file_wait(file, fl) < 0) 263 - log_error(ls, "dlm_posix_unlock: vfs unlock error %llx", 264 - (unsigned long long)number); 261 + /* cause the vfs unlock to return ENOENT if lock is not found */ 262 + fl->fl_flags |= FL_EXISTS; 263 + 264 + rv = posix_lock_file_wait(file, fl); 265 + if (rv == -ENOENT) { 266 + rv = 0; 267 + goto out_free; 268 + } 269 + if (rv < 0) { 270 + log_error(ls, "dlm_posix_unlock: vfs unlock error %d %llx", 271 + rv, (unsigned long long)number); 272 + } 265 273 266 274 op->info.optype = DLM_PLOCK_OP_UNLOCK; 267 275 op->info.pid = fl->fl_pid; ··· 306 296 if (rv == -ENOENT) 307 297 rv = 0; 308 298 299 + out_free: 309 300 kfree(op); 310 301 out: 311 302 dlm_put_lockspace(ls); 303 + fl->fl_flags = fl_flags; 312 304 return rv; 313 305 } 314 306 EXPORT_SYMBOL_GPL(dlm_posix_unlock);