Whamcloud - gitweb
b=24037 avoid conflicting DCACHE_LUSTRE_INVALID
[fs/lustre-release.git] / lustre / llite / vvp_lock.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
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.
11  *
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).
17  *
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
21  *
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
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
30  * Use is subject to license terms.
31  */
32 /*
33  * This file is part of Lustre, http://www.lustre.org/
34  * Lustre is a trademark of Sun Microsystems, Inc.
35  *
36  * Implementation of cl_lock for VVP layer.
37  *
38  *   Author: Nikita Danilov <nikita.danilov@sun.com>
39  */
40
41 #define DEBUG_SUBSYSTEM S_LLITE
42
43 #ifndef __KERNEL__
44 # error This file is kernel only.
45 #endif
46
47 #include <obd.h>
48 #include <lustre_lite.h>
49
50 #include "vvp_internal.h"
51
52 /*****************************************************************************
53  *
54  * Vvp lock functions.
55  *
56  */
57
58 /**
59  * Estimates lock value for the purpose of managing the lock cache during
60  * memory shortages.
61  *
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.
65  */
66 static unsigned long vvp_lock_weigh(const struct lu_env *env,
67                                     const struct cl_lock_slice *slice)
68 {
69         struct ccc_object *cob = cl2ccc(slice->cls_obj);
70
71         ENTRY;
72         RETURN(cfs_atomic_read(&cob->cob_mmap_cnt) > 0 ? ~0UL >> 2 : 0);
73 }
74
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
84 };
85
86 int vvp_lock_init(const struct lu_env *env, struct cl_object *obj,
87                   struct cl_lock *lock, const struct cl_io *io)
88 {
89         return ccc_lock_init(env, obj, lock, io, &vvp_lock_ops);
90 }