Whamcloud - gitweb
LU-6142 llite: Fix style issues for llite_nfs.c
[fs/lustre-release.git] / lustre / llite / lcommon_misc.c
1 /*
2  * GPL HEADER START
3  *
4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License version 2 for more details (a copy is included
14  * in the LICENSE file that accompanied this code).
15  *
16  * You should have received a copy of the GNU General Public License
17  * version 2 along with this program; If not, see
18  * http://www.gnu.org/licenses/gpl-2.0.html
19  *
20  * GPL HEADER END
21  */
22 /*
23  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Use is subject to license terms.
25  *
26  * Copyright (c) 2011, 2017, Intel Corporation.
27  */
28 /*
29  * This file is part of Lustre, http://www.lustre.org/
30  * Lustre is a trademark of Sun Microsystems, Inc.
31  *
32  * cl code used by vvp (and other Lustre clients in the future).
33  *
34  */
35 #define DEBUG_SUBSYSTEM S_LLITE
36 #include <obd_class.h>
37 #include <obd_support.h>
38 #include <obd.h>
39 #include <cl_object.h>
40
41 #include "llite_internal.h"
42
43 /* Initialize the default and maximum LOV EA and cookie sizes.  This allows
44  * us to make MDS RPCs with large enough reply buffers to hold the
45  * maximum-sized (= maximum striped) EA and cookie without having to
46  * calculate this (via a call into the LOV + OSCs) each time we make an RPC. */
47 static int cl_init_ea_size(struct obd_export *md_exp, struct obd_export *dt_exp)
48 {
49         u32 val_size;
50         u32 max_easize;
51         u32 def_easize;
52         int rc;
53         ENTRY;
54
55         val_size = sizeof(max_easize);
56         rc = obd_get_info(NULL, dt_exp, sizeof(KEY_MAX_EASIZE), KEY_MAX_EASIZE,
57                           &val_size, &max_easize);
58         if (rc != 0)
59                 RETURN(rc);
60
61         val_size = sizeof(def_easize);
62         rc = obd_get_info(NULL, dt_exp, sizeof(KEY_DEFAULT_EASIZE),
63                           KEY_DEFAULT_EASIZE, &val_size, &def_easize);
64         if (rc != 0)
65                 RETURN(rc);
66
67         /* default cookiesize is 0 because from 2.4 server doesn't send
68          * llog cookies to client. */
69         CDEBUG(D_HA, "updating def/max_easize: %d/%d\n",
70                def_easize, max_easize);
71
72         rc = md_init_ea_size(md_exp, max_easize, def_easize);
73         RETURN(rc);
74 }
75
76 /**
77  * This function is used as an upcall-callback hooked llite clients
78  * into obd_notify() listeners chain to handle notifications about
79  * change of import connect_flags. See lustre_common_fill_super().
80  */
81 int cl_ocd_update(struct obd_device *host, struct obd_device *watched,
82                   enum obd_notify_event ev, void *owner)
83 {
84         struct lustre_client_ocd *lco;
85         struct client_obd        *cli;
86         __u64 flags;
87         int   result;
88
89         ENTRY;
90         if (!strcmp(watched->obd_type->typ_name, LUSTRE_OSC_NAME) &&
91             watched->obd_set_up && !watched->obd_stopping) {
92                 cli = &watched->u.cli;
93                 lco = owner;
94                 flags = cli->cl_import->imp_connect_data.ocd_connect_flags;
95                 CDEBUG(D_SUPER, "Changing connect_flags: %#llx -> %#llx\n",
96                        lco->lco_flags, flags);
97                 mutex_lock(&lco->lco_lock);
98                 lco->lco_flags &= flags;
99                 /* for each osc event update ea size */
100                 if (lco->lco_dt_exp)
101                         cl_init_ea_size(lco->lco_md_exp, lco->lco_dt_exp);
102
103                 mutex_unlock(&lco->lco_lock);
104                 result = 0;
105         } else {
106                 CERROR("unexpected notification from %s %s"
107                        "(setup:%d,stopping:%d)!\n",
108                        watched->obd_type->typ_name,
109                        watched->obd_name, watched->obd_set_up,
110                        watched->obd_stopping);
111                 result = -EINVAL;
112         }
113         RETURN(result);
114 }
115
116 #define GROUPLOCK_SCOPE "grouplock"
117
118 int cl_get_grouplock(struct cl_object *obj, unsigned long gid, int nonblock,
119                      struct ll_grouplock *lg)
120 {
121         struct lu_env          *env;
122         struct cl_io           *io;
123         struct cl_lock         *lock;
124         struct cl_lock_descr   *descr;
125         __u32                   enqflags;
126         __u16                   refcheck;
127         int                     rc;
128
129         env = cl_env_get(&refcheck);
130         if (IS_ERR(env))
131                 return PTR_ERR(env);
132
133         io = vvp_env_thread_io(env);
134         io->ci_obj = obj;
135
136         rc = cl_io_init(env, io, CIT_MISC, io->ci_obj);
137         if (rc != 0) {
138                 cl_io_fini(env, io);
139                 cl_env_put(env, &refcheck);
140                 /* Does not make sense to take GL for released layout */
141                 if (rc > 0)
142                         rc = -ENOTSUPP;
143                 return rc;
144         }
145
146         lock = vvp_env_lock(env);
147         descr = &lock->cll_descr;
148         descr->cld_obj = obj;
149         descr->cld_start = 0;
150         descr->cld_end = CL_PAGE_EOF;
151         descr->cld_gid = gid;
152         descr->cld_mode = CLM_GROUP;
153
154         enqflags = CEF_MUST | (nonblock ? CEF_NONBLOCK : 0);
155         descr->cld_enq_flags = enqflags;
156
157         rc = cl_lock_request(env, io, lock);
158         if (rc < 0) {
159                 cl_io_fini(env, io);
160                 cl_env_put(env, &refcheck);
161                 return rc;
162         }
163
164         lg->lg_env = env;
165         lg->lg_io = io;
166         lg->lg_lock = lock;
167         lg->lg_gid = gid;
168
169         return 0;
170 }
171
172 void cl_put_grouplock(struct ll_grouplock *lg)
173 {
174         struct lu_env  *env  = lg->lg_env;
175         struct cl_io   *io   = lg->lg_io;
176         struct cl_lock *lock = lg->lg_lock;
177
178         LASSERT(lg->lg_env != NULL);
179         LASSERT(lg->lg_gid != 0);
180
181         cl_lock_release(env, lock);
182         cl_io_fini(env, io);
183         cl_env_put(env, NULL);
184 }