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.
32 * Copyright (c) 2011 Whamcloud, Inc.
36 * This file is part of Lustre, http://www.lustre.org/
37 * Lustre is a trademark of Sun Microsystems, Inc.
39 * cl code shared between vvp and liblustre (and other Lustre clients in the
43 #include <obd_class.h>
44 #include <obd_support.h>
46 #include <cl_object.h>
49 #include <lustre_lite.h>
52 /* Initialize the default and maximum LOV EA and cookie sizes. This allows
53 * us to make MDS RPCs with large enough reply buffers to hold the
54 * maximum-sized (= maximum striped) EA and cookie without having to
55 * calculate this (via a call into the LOV + OSCs) each time we make an RPC. */
56 int cl_init_ea_size(struct obd_export *md_exp, struct obd_export *dt_exp)
58 struct lov_stripe_md lsm = { .lsm_magic = LOV_MAGIC_V3 };
59 __u32 valsize = sizeof(struct lov_desc);
60 int rc, easize, def_easize, cookiesize;
65 rc = obd_get_info(dt_exp, sizeof(KEY_LOVDESC), KEY_LOVDESC,
66 &valsize, &desc, NULL);
70 stripes = min(desc.ld_tgt_count, (__u32)LOV_MAX_STRIPE_COUNT);
71 lsm.lsm_stripe_count = stripes;
72 easize = obd_size_diskmd(dt_exp, &lsm);
74 lsm.lsm_stripe_count = desc.ld_default_stripe_count;
75 def_easize = obd_size_diskmd(dt_exp, &lsm);
77 cookiesize = stripes * sizeof(struct llog_cookie);
79 CDEBUG(D_HA, "updating max_mdsize/max_cookiesize: %d/%d\n",
82 rc = md_init_ea_size(md_exp, easize, def_easize, cookiesize);
87 * This function is used as an upcall-callback hooked by liblustre and llite
88 * clients into obd_notify() listeners chain to handle notifications about
89 * change of import connect_flags. See llu_fsswop_mount() and
90 * lustre_common_fill_super().
92 int cl_ocd_update(struct obd_device *host,
93 struct obd_device *watched,
94 enum obd_notify_event ev, void *owner, void *data)
96 struct lustre_client_ocd *lco;
97 struct client_obd *cli;
102 if (!strcmp(watched->obd_type->typ_name, LUSTRE_OSC_NAME)) {
103 cli = &watched->u.cli;
105 flags = cli->cl_import->imp_connect_data.ocd_connect_flags;
106 CDEBUG(D_SUPER, "Changing connect_flags: "LPX64" -> "LPX64"\n",
107 lco->lco_flags, flags);
108 cfs_mutex_down(&lco->lco_lock);
109 lco->lco_flags &= flags;
110 /* for each osc event update ea size */
112 cl_init_ea_size(lco->lco_md_exp, lco->lco_dt_exp);
114 cfs_mutex_up(&lco->lco_lock);
117 CERROR("unexpected notification from %s %s!\n",
118 watched->obd_type->typ_name,
125 #define GROUPLOCK_SCOPE "grouplock"
127 int cl_get_grouplock(struct cl_object *obj, unsigned long gid, int nonblock,
128 struct ccc_grouplock *cg)
132 struct cl_lock *lock;
133 struct cl_lock_descr *descr;
138 env = cl_env_get(&refcheck);
142 io = ccc_env_thread_io(env);
145 rc = cl_io_init(env, io, CIT_MISC, io->ci_obj);
148 cl_env_put(env, &refcheck);
152 descr = &ccc_env_info(env)->cti_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 lock = cl_lock_request(env, io, descr, GROUPLOCK_SCOPE, cfs_current());
165 cl_env_put(env, &refcheck);
166 return PTR_ERR(lock);
169 cg->cg_env = cl_env_get(&refcheck);
173 LASSERT(cg->cg_env == env);
175 cl_env_unplant(env, &refcheck);
179 void cl_put_grouplock(struct ccc_grouplock *cg)
181 struct lu_env *env = cg->cg_env;
182 struct cl_io *io = cg->cg_io;
183 struct cl_lock *lock = cg->cg_lock;
189 cl_env_implant(env, &refcheck);
190 cl_env_put(env, &refcheck);
193 cl_lock_release(env, lock, GROUPLOCK_SCOPE, cfs_current());
195 cl_env_put(env, NULL);