+#include <lustre_dlm.h>
+#include <lustre_lib.h>
+
+/*
+ * ldlm locking uses resource to serialize access to locks
+ * but there is a case when we change resource of lock upon
+ * enqueue reply. we rely on that lock->l_resource = new_res
+ * is atomic
+ */
+struct ldlm_resource * lock_res_and_lock(struct ldlm_lock *lock)
+{
+ struct ldlm_resource *res = lock->l_resource;
+
+ if (ns_is_server(res->lr_namespace)) {
+ /* on server-side resource of lock doesn't change */
+ lock_res(res);
+ return res;
+ }
+
+ spin_lock(&lock->l_lock);
+ res = lock->l_resource;
+ lock_res(res);
+ return res;
+}
+
+void unlock_res_and_lock(struct ldlm_lock *lock)
+{
+ struct ldlm_resource *res = lock->l_resource;
+
+ if (ns_is_server(res->lr_namespace)) {
+ /* on server-side resource of lock doesn't change */
+ unlock_res(res);
+ return;
+ }
+
+ unlock_res(res);
+ spin_unlock(&lock->l_lock);
+}