4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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
23 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
31 * cl code used by vvp (and other Lustre clients in the future).
34 #define DEBUG_SUBSYSTEM S_LLITE
35 #include <obd_class.h>
36 #include <obd_support.h>
38 #include <cl_object.h>
40 #include "llite_internal.h"
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.
48 static int cl_init_ea_size(struct obd_export *md_exp, struct obd_export *dt_exp)
57 val_size = sizeof(max_easize);
58 rc = obd_get_info(NULL, dt_exp, sizeof(KEY_MAX_EASIZE), KEY_MAX_EASIZE,
59 &val_size, &max_easize);
63 val_size = sizeof(def_easize);
64 rc = obd_get_info(NULL, dt_exp, sizeof(KEY_DEFAULT_EASIZE),
65 KEY_DEFAULT_EASIZE, &val_size, &def_easize);
70 * default cookiesize is 0 because from 2.4 server doesn't send
71 * llog cookies to client.
73 CDEBUG(D_HA, "updating def/max_easize: %d/%d\n",
74 def_easize, max_easize);
76 rc = md_init_ea_size(md_exp, max_easize, def_easize);
81 * This function is used as an upcall-callback hooked llite clients
82 * into obd_notify() listeners chain to handle notifications about
83 * change of import connect_flags. See lustre_common_fill_super().
85 int cl_ocd_update(struct obd_device *host, struct obd_device *watched,
86 enum obd_notify_event ev, void *owner)
88 struct lustre_client_ocd *lco;
89 struct client_obd *cli;
95 if (!strcmp(watched->obd_type->typ_name, LUSTRE_OSC_NAME) &&
96 watched->obd_set_up && !watched->obd_stopping) {
97 cli = &watched->u.cli;
99 flags = cli->cl_import->imp_connect_data.ocd_connect_flags;
100 CDEBUG(D_SUPER, "Changing connect_flags: %#llx -> %#llx\n",
101 lco->lco_flags, flags);
102 mutex_lock(&lco->lco_lock);
103 lco->lco_flags &= flags;
104 /* for each osc event update ea size */
106 cl_init_ea_size(lco->lco_md_exp, lco->lco_dt_exp);
108 mutex_unlock(&lco->lco_lock);
111 CERROR("unexpected notification from %s %s"
112 "(setup:%d,stopping:%d)!\n",
113 watched->obd_type->typ_name,
114 watched->obd_name, watched->obd_set_up,
115 watched->obd_stopping);
121 #define GROUPLOCK_SCOPE "grouplock"
123 int cl_get_grouplock(struct cl_object *obj, unsigned long gid, int nonblock,
124 struct ll_grouplock *lg)
128 struct cl_lock *lock;
129 struct cl_lock_descr *descr;
134 env = cl_env_get(&refcheck);
138 io = vvp_env_thread_io(env);
141 rc = cl_io_init(env, io, CIT_MISC, io->ci_obj);
144 cl_env_put(env, &refcheck);
145 /* Does not make sense to take GL for released layout */
151 lock = vvp_env_lock(env);
152 descr = &lock->cll_descr;
153 descr->cld_obj = obj;
154 descr->cld_start = 0;
155 descr->cld_end = CL_PAGE_EOF;
156 descr->cld_gid = gid;
157 descr->cld_mode = CLM_GROUP;
159 enqflags = CEF_MUST | (nonblock ? CEF_NONBLOCK : 0);
160 descr->cld_enq_flags = enqflags;
162 rc = cl_lock_request(env, io, lock);
165 cl_env_put(env, &refcheck);
177 void cl_put_grouplock(struct ll_grouplock *lg)
179 struct lu_env *env = lg->lg_env;
180 struct cl_io *io = lg->lg_io;
181 struct cl_lock *lock = lg->lg_lock;
183 LASSERT(lg->lg_env != NULL);
184 LASSERT(lg->lg_gid != 0);
186 cl_lock_release(env, lock);
188 cl_env_put(env, NULL);