Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 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 |
Oleg Drokin | 6a5b99a | 2016-06-14 23:33:40 -0400 | [diff] [blame] | 18 | * http://www.gnu.org/licenses/gpl-2.0.html |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 19 | * |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 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, 2012, 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 shared between vvp and liblustre (and other Lustre clients in the |
| 33 | * future). |
| 34 | * |
| 35 | */ |
Greg Kroah-Hartman | 67a235f | 2014-07-11 21:51:41 -0700 | [diff] [blame] | 36 | #include "../include/obd_class.h" |
| 37 | #include "../include/obd_support.h" |
| 38 | #include "../include/obd.h" |
| 39 | #include "../include/cl_object.h" |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 40 | |
John Hammond | 98eae5e | 2016-03-30 19:48:55 -0400 | [diff] [blame] | 41 | #include "llite_internal.h" |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 42 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 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 |
Oleg Drokin | ec9a1ac | 2016-02-24 22:00:28 -0500 | [diff] [blame] | 46 | * calculate this (via a call into the LOV + OSCs) each time we make an RPC. |
| 47 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 48 | int cl_init_ea_size(struct obd_export *md_exp, struct obd_export *dt_exp) |
| 49 | { |
| 50 | struct lov_stripe_md lsm = { .lsm_magic = LOV_MAGIC_V3 }; |
| 51 | __u32 valsize = sizeof(struct lov_desc); |
| 52 | int rc, easize, def_easize, cookiesize; |
| 53 | struct lov_desc desc; |
Brian Behlendorf | 4477934 | 2014-04-27 13:06:47 -0400 | [diff] [blame] | 54 | __u16 stripes, def_stripes; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 55 | |
| 56 | rc = obd_get_info(NULL, dt_exp, sizeof(KEY_LOVDESC), KEY_LOVDESC, |
| 57 | &valsize, &desc, NULL); |
| 58 | if (rc) |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 59 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 60 | |
Anil Belur | 2df2b3a | 2014-06-18 18:23:51 +1000 | [diff] [blame] | 61 | stripes = min_t(__u32, desc.ld_tgt_count, LOV_MAX_STRIPE_COUNT); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 62 | lsm.lsm_stripe_count = stripes; |
| 63 | easize = obd_size_diskmd(dt_exp, &lsm); |
| 64 | |
Brian Behlendorf | 4477934 | 2014-04-27 13:06:47 -0400 | [diff] [blame] | 65 | def_stripes = min_t(__u32, desc.ld_default_stripe_count, |
| 66 | LOV_MAX_STRIPE_COUNT); |
| 67 | lsm.lsm_stripe_count = def_stripes; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 68 | def_easize = obd_size_diskmd(dt_exp, &lsm); |
| 69 | |
| 70 | cookiesize = stripes * sizeof(struct llog_cookie); |
| 71 | |
Brian Behlendorf | 4477934 | 2014-04-27 13:06:47 -0400 | [diff] [blame] | 72 | /* default cookiesize is 0 because from 2.4 server doesn't send |
Oleg Drokin | ec9a1ac | 2016-02-24 22:00:28 -0500 | [diff] [blame] | 73 | * llog cookies to client. |
| 74 | */ |
Brian Behlendorf | 4477934 | 2014-04-27 13:06:47 -0400 | [diff] [blame] | 75 | CDEBUG(D_HA, |
| 76 | "updating def/max_easize: %d/%d def/max_cookiesize: 0/%d\n", |
| 77 | def_easize, easize, cookiesize); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 78 | |
Brian Behlendorf | 4477934 | 2014-04-27 13:06:47 -0400 | [diff] [blame] | 79 | rc = md_init_ea_size(md_exp, easize, def_easize, cookiesize, 0); |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 80 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | /** |
| 84 | * This function is used as an upcall-callback hooked by liblustre and llite |
| 85 | * clients into obd_notify() listeners chain to handle notifications about |
| 86 | * change of import connect_flags. See llu_fsswop_mount() and |
| 87 | * lustre_common_fill_super(). |
| 88 | */ |
| 89 | int cl_ocd_update(struct obd_device *host, |
| 90 | struct obd_device *watched, |
| 91 | enum obd_notify_event ev, void *owner, void *data) |
| 92 | { |
| 93 | struct lustre_client_ocd *lco; |
| 94 | struct client_obd *cli; |
| 95 | __u64 flags; |
| 96 | int result; |
| 97 | |
Yang Sheng | 2323d6d | 2016-06-20 16:55:42 -0400 | [diff] [blame] | 98 | if (!strcmp(watched->obd_type->typ_name, LUSTRE_OSC_NAME) && |
| 99 | watched->obd_set_up && !watched->obd_stopping) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 100 | cli = &watched->u.cli; |
| 101 | lco = owner; |
| 102 | flags = cli->cl_import->imp_connect_data.ocd_connect_flags; |
Greg Kroah-Hartman | 55f5a82 | 2014-07-12 20:26:07 -0700 | [diff] [blame] | 103 | CDEBUG(D_SUPER, "Changing connect_flags: %#llx -> %#llx\n", |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 104 | lco->lco_flags, flags); |
| 105 | mutex_lock(&lco->lco_lock); |
| 106 | lco->lco_flags &= flags; |
| 107 | /* for each osc event update ea size */ |
| 108 | if (lco->lco_dt_exp) |
| 109 | cl_init_ea_size(lco->lco_md_exp, lco->lco_dt_exp); |
| 110 | |
| 111 | mutex_unlock(&lco->lco_lock); |
| 112 | result = 0; |
| 113 | } else { |
Yang Sheng | 2323d6d | 2016-06-20 16:55:42 -0400 | [diff] [blame] | 114 | CERROR("unexpected notification from %s %s (setup:%d,stopping:%d)!\n", |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 115 | watched->obd_type->typ_name, |
Yang Sheng | 2323d6d | 2016-06-20 16:55:42 -0400 | [diff] [blame] | 116 | watched->obd_name, watched->obd_set_up, |
| 117 | watched->obd_stopping); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 118 | result = -EINVAL; |
| 119 | } |
Greg Kroah-Hartman | 0a3bdb0 | 2013-08-03 10:35:28 +0800 | [diff] [blame] | 120 | return result; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | #define GROUPLOCK_SCOPE "grouplock" |
| 124 | |
| 125 | int cl_get_grouplock(struct cl_object *obj, unsigned long gid, int nonblock, |
John Hammond | 98eae5e | 2016-03-30 19:48:55 -0400 | [diff] [blame] | 126 | struct ll_grouplock *cg) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 127 | { |
| 128 | struct lu_env *env; |
| 129 | struct cl_io *io; |
| 130 | struct cl_lock *lock; |
| 131 | struct cl_lock_descr *descr; |
| 132 | __u32 enqflags; |
| 133 | int refcheck; |
| 134 | int rc; |
| 135 | |
| 136 | env = cl_env_get(&refcheck); |
| 137 | if (IS_ERR(env)) |
| 138 | return PTR_ERR(env); |
| 139 | |
John Hammond | 9acc450 | 2016-03-30 19:48:57 -0400 | [diff] [blame] | 140 | io = vvp_env_thread_io(env); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 141 | io->ci_obj = obj; |
| 142 | io->ci_ignore_layout = 1; |
| 143 | |
| 144 | rc = cl_io_init(env, io, CIT_MISC, io->ci_obj); |
Jinshan Xiong | 06563b5 | 2016-03-30 19:48:40 -0400 | [diff] [blame] | 145 | if (rc != 0) { |
Jinshan Xiong | 26f98e8 | 2016-03-30 19:48:25 -0400 | [diff] [blame] | 146 | cl_io_fini(env, io); |
| 147 | cl_env_put(env, &refcheck); |
Jinshan Xiong | 48d23e6 | 2013-12-03 21:58:48 +0800 | [diff] [blame] | 148 | /* Does not make sense to take GL for released layout */ |
| 149 | if (rc > 0) |
| 150 | rc = -ENOTSUPP; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 151 | return rc; |
| 152 | } |
| 153 | |
John Hammond | 9acc450 | 2016-03-30 19:48:57 -0400 | [diff] [blame] | 154 | lock = vvp_env_lock(env); |
Jinshan Xiong | 06563b5 | 2016-03-30 19:48:40 -0400 | [diff] [blame] | 155 | descr = &lock->cll_descr; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 156 | descr->cld_obj = obj; |
| 157 | descr->cld_start = 0; |
| 158 | descr->cld_end = CL_PAGE_EOF; |
| 159 | descr->cld_gid = gid; |
| 160 | descr->cld_mode = CLM_GROUP; |
| 161 | |
| 162 | enqflags = CEF_MUST | (nonblock ? CEF_NONBLOCK : 0); |
| 163 | descr->cld_enq_flags = enqflags; |
| 164 | |
Jinshan Xiong | 06563b5 | 2016-03-30 19:48:40 -0400 | [diff] [blame] | 165 | rc = cl_lock_request(env, io, lock); |
| 166 | if (rc < 0) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 167 | cl_io_fini(env, io); |
| 168 | cl_env_put(env, &refcheck); |
Jinshan Xiong | 06563b5 | 2016-03-30 19:48:40 -0400 | [diff] [blame] | 169 | return rc; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 170 | } |
| 171 | |
John Hammond | 98eae5e | 2016-03-30 19:48:55 -0400 | [diff] [blame] | 172 | cg->lg_env = cl_env_get(&refcheck); |
| 173 | cg->lg_io = io; |
| 174 | cg->lg_lock = lock; |
| 175 | cg->lg_gid = gid; |
| 176 | LASSERT(cg->lg_env == env); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 177 | |
| 178 | cl_env_unplant(env, &refcheck); |
| 179 | return 0; |
| 180 | } |
| 181 | |
John Hammond | 98eae5e | 2016-03-30 19:48:55 -0400 | [diff] [blame] | 182 | void cl_put_grouplock(struct ll_grouplock *cg) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 183 | { |
John Hammond | 98eae5e | 2016-03-30 19:48:55 -0400 | [diff] [blame] | 184 | struct lu_env *env = cg->lg_env; |
| 185 | struct cl_io *io = cg->lg_io; |
| 186 | struct cl_lock *lock = cg->lg_lock; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 187 | int refcheck; |
| 188 | |
John Hammond | 98eae5e | 2016-03-30 19:48:55 -0400 | [diff] [blame] | 189 | LASSERT(cg->lg_env); |
| 190 | LASSERT(cg->lg_gid); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 191 | |
| 192 | cl_env_implant(env, &refcheck); |
| 193 | cl_env_put(env, &refcheck); |
| 194 | |
Jinshan Xiong | 06563b5 | 2016-03-30 19:48:40 -0400 | [diff] [blame] | 195 | cl_lock_release(env, lock); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 196 | cl_io_fini(env, io); |
| 197 | cl_env_put(env, NULL); |
| 198 | } |