1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
36 * Implementation of cl_lock for VVP layer.
38 * Author: Nikita Danilov <nikita.danilov@sun.com>
41 #define DEBUG_SUBSYSTEM S_LLITE
44 # error This file is kernel only.
48 #include <lustre_lite.h>
50 #include "vvp_internal.h"
52 /*****************************************************************************
59 * Estimates lock value for the purpose of managing the lock cache during
62 * Locks for memory mapped files are almost infinitely precious, others are
63 * junk. "Mapped locks" are heavy, but not infinitely heavy, so that they are
64 * ordered within themselves by weights assigned from other layers.
66 static unsigned long vvp_lock_weigh(const struct lu_env *env,
67 const struct cl_lock_slice *slice)
69 struct ccc_object *cob = cl2ccc(slice->cls_obj);
72 RETURN(cfs_atomic_read(&cob->cob_mmap_cnt) > 0 ? ~0UL >> 2 : 0);
75 static const struct cl_lock_operations vvp_lock_ops = {
76 .clo_delete = ccc_lock_delete,
77 .clo_fini = ccc_lock_fini,
78 .clo_enqueue = ccc_lock_enqueue,
79 .clo_wait = ccc_lock_wait,
80 .clo_unuse = ccc_lock_unuse,
81 .clo_fits_into = ccc_lock_fits_into,
82 .clo_state = ccc_lock_state,
83 .clo_weigh = vvp_lock_weigh
86 int vvp_lock_init(const struct lu_env *env, struct cl_object *obj,
87 struct cl_lock *lock, const struct cl_io *io)
89 return ccc_lock_init(env, obj, lock, io, &vvp_lock_ops);