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