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) 2007, 2010, Oracle and/or its affiliates. All rights reserved. |
| 24 | * Use is subject to license terms. |
| 25 | * |
Andreas Dilger | 1dc563a | 2015-11-08 18:09:37 -0500 | [diff] [blame] | 26 | * Copyright (c) 2011, 2015, Intel Corporation. |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 27 | */ |
| 28 | /* |
| 29 | * This file is part of Lustre, http://www.lustre.org/ |
| 30 | * Lustre is a trademark of Sun Microsystems, Inc. |
| 31 | */ |
| 32 | |
| 33 | #ifndef __OBD_H |
| 34 | #define __OBD_H |
| 35 | |
John L. Hammond | 7d53d8f | 2016-03-30 19:48:36 -0400 | [diff] [blame] | 36 | #include <linux/spinlock.h> |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 37 | |
| 38 | #define IOC_OSC_TYPE 'h' |
| 39 | #define IOC_OSC_MIN_NR 20 |
| 40 | #define IOC_OSC_SET_ACTIVE _IOWR(IOC_OSC_TYPE, 21, struct obd_device *) |
| 41 | #define IOC_OSC_MAX_NR 50 |
| 42 | |
| 43 | #define IOC_MDC_TYPE 'i' |
| 44 | #define IOC_MDC_MIN_NR 20 |
| 45 | #define IOC_MDC_MAX_NR 50 |
| 46 | |
Greg Kroah-Hartman | 1accaad | 2014-07-11 21:34:24 -0700 | [diff] [blame] | 47 | #include "lustre/lustre_idl.h" |
| 48 | #include "lustre_lib.h" |
Greg Kroah-Hartman | 1accaad | 2014-07-11 21:34:24 -0700 | [diff] [blame] | 49 | #include "lu_ref.h" |
| 50 | #include "lustre_export.h" |
| 51 | #include "lustre_fid.h" |
| 52 | #include "lustre_fld.h" |
Oleg Drokin | bb41292 | 2016-03-30 19:48:38 -0400 | [diff] [blame] | 53 | #include "lustre_intent.h" |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 54 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 55 | #define MAX_OBD_DEVICES 8192 |
| 56 | |
| 57 | struct osc_async_rc { |
| 58 | int ar_rc; |
| 59 | int ar_force_sync; |
| 60 | __u64 ar_min_xid; |
| 61 | }; |
| 62 | |
| 63 | struct lov_oinfo { /* per-stripe data structure */ |
| 64 | struct ost_id loi_oi; /* object ID/Sequence on the target OST */ |
| 65 | int loi_ost_idx; /* OST stripe index in lov_tgt_desc->tgts */ |
| 66 | int loi_ost_gen; /* generation of this loi_ost_idx */ |
| 67 | |
| 68 | unsigned long loi_kms_valid:1; |
| 69 | __u64 loi_kms; /* known minimum size */ |
| 70 | struct ost_lvb loi_lvb; |
| 71 | struct osc_async_rc loi_ar; |
| 72 | }; |
| 73 | |
| 74 | static inline void loi_kms_set(struct lov_oinfo *oinfo, __u64 kms) |
| 75 | { |
| 76 | oinfo->loi_kms = kms; |
| 77 | oinfo->loi_kms_valid = 1; |
| 78 | } |
| 79 | |
| 80 | static inline void loi_init(struct lov_oinfo *loi) |
| 81 | { |
| 82 | } |
| 83 | |
| 84 | struct lov_stripe_md { |
| 85 | atomic_t lsm_refc; |
| 86 | spinlock_t lsm_lock; |
| 87 | pid_t lsm_lock_owner; /* debugging */ |
| 88 | |
| 89 | /* maximum possible file size, might change as OSTs status changes, |
Oleg Drokin | c56e256 | 2016-02-24 22:00:25 -0500 | [diff] [blame] | 90 | * e.g. disconnected, deactivated |
| 91 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 92 | __u64 lsm_maxbytes; |
| 93 | struct { |
| 94 | /* Public members. */ |
| 95 | struct ost_id lw_object_oi; /* lov object id/seq */ |
| 96 | |
| 97 | /* LOV-private members start here -- only for use in lov/. */ |
| 98 | __u32 lw_magic; |
| 99 | __u32 lw_stripe_size; /* size of the stripe */ |
| 100 | __u32 lw_pattern; /* striping pattern (RAID0, RAID1) */ |
| 101 | __u16 lw_stripe_count; /* number of objects being striped over */ |
| 102 | __u16 lw_layout_gen; /* generation of the layout */ |
| 103 | char lw_pool_name[LOV_MAXPOOLNAME]; /* pool name */ |
| 104 | } lsm_wire; |
| 105 | |
| 106 | struct lov_oinfo *lsm_oinfo[0]; |
| 107 | }; |
| 108 | |
| 109 | #define lsm_oi lsm_wire.lw_object_oi |
| 110 | #define lsm_magic lsm_wire.lw_magic |
| 111 | #define lsm_layout_gen lsm_wire.lw_layout_gen |
| 112 | #define lsm_stripe_size lsm_wire.lw_stripe_size |
| 113 | #define lsm_pattern lsm_wire.lw_pattern |
| 114 | #define lsm_stripe_count lsm_wire.lw_stripe_count |
| 115 | #define lsm_pool_name lsm_wire.lw_pool_name |
| 116 | |
Jinshan Xiong | 5dd1641 | 2013-07-23 00:06:39 +0800 | [diff] [blame] | 117 | static inline bool lsm_is_released(struct lov_stripe_md *lsm) |
| 118 | { |
| 119 | return !!(lsm->lsm_pattern & LOV_PATTERN_F_RELEASED); |
| 120 | } |
| 121 | |
| 122 | static inline bool lsm_has_objects(struct lov_stripe_md *lsm) |
| 123 | { |
Oleg Drokin | d2a1398 | 2016-02-16 00:46:52 -0500 | [diff] [blame] | 124 | if (!lsm) |
Jinshan Xiong | 5dd1641 | 2013-07-23 00:06:39 +0800 | [diff] [blame] | 125 | return false; |
| 126 | if (lsm_is_released(lsm)) |
| 127 | return false; |
| 128 | return true; |
| 129 | } |
| 130 | |
John L. Hammond | 081b726 | 2014-04-27 13:06:40 -0400 | [diff] [blame] | 131 | static inline int lov_stripe_md_size(unsigned int stripe_count) |
| 132 | { |
| 133 | struct lov_stripe_md lsm; |
| 134 | |
| 135 | return sizeof(lsm) + stripe_count * sizeof(lsm.lsm_oinfo[0]); |
| 136 | } |
| 137 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 138 | struct obd_info; |
| 139 | |
| 140 | typedef int (*obd_enqueue_update_f)(void *cookie, int rc); |
| 141 | |
| 142 | /* obd info for a particular level (lov, osc). */ |
| 143 | struct obd_info { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 144 | /* Flags used for set request specific flags: |
| 145 | - while lock handling, the flags obtained on the enqueue |
| 146 | request are set here. |
| 147 | - while stats, the flags used for control delay/resend. |
| 148 | - while setattr, the flags used for distinguish punch operation |
| 149 | */ |
| 150 | __u64 oi_flags; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 151 | /* lsm data specific for every OSC. */ |
| 152 | struct lov_stripe_md *oi_md; |
| 153 | /* obdo data specific for every OSC, if needed at all. */ |
| 154 | struct obdo *oi_oa; |
| 155 | /* statfs data specific for every OSC, if needed at all. */ |
| 156 | struct obd_statfs *oi_osfs; |
| 157 | /* An update callback which is called to update some data on upper |
Masanari Iida | 1789118 | 2014-03-08 22:58:33 +0900 | [diff] [blame] | 158 | * level. E.g. it is used for update lsm->lsm_oinfo at every received |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 159 | * request in osc level for enqueue requests. It is also possible to |
Oleg Drokin | c56e256 | 2016-02-24 22:00:25 -0500 | [diff] [blame] | 160 | * update some caller data from LOV layer if needed. |
| 161 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 162 | obd_enqueue_update_f oi_cb_up; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 163 | }; |
| 164 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 165 | struct obd_type { |
| 166 | struct list_head typ_chain; |
| 167 | struct obd_ops *typ_dt_ops; |
| 168 | struct md_ops *typ_md_ops; |
Dmitry Eremin | 61e87ab | 2015-05-21 15:32:27 -0400 | [diff] [blame] | 169 | struct dentry *typ_debugfs_entry; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 170 | char *typ_name; |
| 171 | int typ_refcnt; |
| 172 | struct lu_device_type *typ_lu; |
| 173 | spinlock_t obd_type_lock; |
Oleg Drokin | 9b80130 | 2015-05-21 15:32:16 -0400 | [diff] [blame] | 174 | struct kobject *typ_kobj; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 175 | }; |
| 176 | |
| 177 | struct brw_page { |
Oleg Drokin | 21aef7d | 2014-08-15 12:55:56 -0400 | [diff] [blame] | 178 | u64 off; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 179 | struct page *pg; |
| 180 | int count; |
Oleg Drokin | 21aef7d | 2014-08-15 12:55:56 -0400 | [diff] [blame] | 181 | u32 flag; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 182 | }; |
| 183 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 184 | /* llog contexts */ |
| 185 | enum llog_ctxt_id { |
| 186 | LLOG_CONFIG_ORIG_CTXT = 0, |
| 187 | LLOG_CONFIG_REPL_CTXT, |
| 188 | LLOG_MDS_OST_ORIG_CTXT, |
| 189 | LLOG_MDS_OST_REPL_CTXT, |
| 190 | LLOG_SIZE_ORIG_CTXT, |
| 191 | LLOG_SIZE_REPL_CTXT, |
| 192 | LLOG_RD1_ORIG_CTXT, |
| 193 | LLOG_RD1_REPL_CTXT, |
| 194 | LLOG_TEST_ORIG_CTXT, |
| 195 | LLOG_TEST_REPL_CTXT, |
| 196 | LLOG_LOVEA_ORIG_CTXT, |
| 197 | LLOG_LOVEA_REPL_CTXT, |
jcl | 99a9226 | 2013-07-23 00:07:07 +0800 | [diff] [blame] | 198 | LLOG_CHANGELOG_ORIG_CTXT, /**< changelog generation on mdd */ |
| 199 | LLOG_CHANGELOG_REPL_CTXT, /**< changelog access on clients */ |
| 200 | LLOG_CHANGELOG_USER_ORIG_CTXT, /**< for multiple changelog consumers */ |
| 201 | LLOG_AGENT_ORIG_CTXT, /**< agent requests generation on cdt */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 202 | LLOG_MAX_CTXTS |
| 203 | }; |
| 204 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 205 | struct timeout_item { |
| 206 | enum timeout_event ti_event; |
Greg Kroah-Hartman | a649ad1 | 2014-07-12 00:27:46 -0700 | [diff] [blame] | 207 | unsigned long ti_timeout; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 208 | timeout_cb_t ti_cb; |
| 209 | void *ti_cb_data; |
| 210 | struct list_head ti_obd_list; |
| 211 | struct list_head ti_chain; |
| 212 | }; |
| 213 | |
| 214 | #define OSC_MAX_RIF_DEFAULT 8 |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 215 | #define OSC_MAX_RIF_MAX 256 |
| 216 | #define OSC_MAX_DIRTY_DEFAULT (OSC_MAX_RIF_DEFAULT * 4) |
| 217 | #define OSC_MAX_DIRTY_MB_MAX 2048 /* arbitrary, but < MAX_LONG bytes */ |
| 218 | #define OSC_DEFAULT_RESENDS 10 |
| 219 | |
| 220 | /* possible values for fo_sync_lock_cancel */ |
| 221 | enum { |
| 222 | NEVER_SYNC_ON_CANCEL = 0, |
| 223 | BLOCKING_SYNC_ON_CANCEL = 1, |
| 224 | ALWAYS_SYNC_ON_CANCEL = 2, |
| 225 | NUM_SYNC_ON_CANCEL_STATES |
| 226 | }; |
| 227 | |
| 228 | #define MDC_MAX_RIF_DEFAULT 8 |
| 229 | #define MDC_MAX_RIF_MAX 512 |
| 230 | |
Andreas Dilger | 9936913 | 2016-06-20 16:55:52 -0400 | [diff] [blame] | 231 | enum obd_cl_sem_lock_class { |
| 232 | OBD_CLI_SEM_NORMAL, |
| 233 | OBD_CLI_SEM_MGC, |
| 234 | OBD_CLI_SEM_MDCOSC, |
| 235 | }; |
| 236 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 237 | struct mdc_rpc_lock; |
| 238 | struct obd_import; |
| 239 | struct client_obd { |
| 240 | struct rw_semaphore cl_sem; |
| 241 | struct obd_uuid cl_target_uuid; |
| 242 | struct obd_import *cl_import; /* ptlrpc connection state */ |
| 243 | int cl_conn_count; |
| 244 | /* max_mds_easize is purely a performance thing so we don't have to |
Oleg Drokin | c56e256 | 2016-02-24 22:00:25 -0500 | [diff] [blame] | 245 | * call obd_size_diskmd() all the time. |
| 246 | */ |
Brian Behlendorf | 4477934 | 2014-04-27 13:06:47 -0400 | [diff] [blame] | 247 | int cl_default_mds_easize; |
| 248 | int cl_max_mds_easize; |
| 249 | int cl_default_mds_cookiesize; |
| 250 | int cl_max_mds_cookiesize; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 251 | |
| 252 | enum lustre_sec_part cl_sp_me; |
| 253 | enum lustre_sec_part cl_sp_to; |
| 254 | struct sptlrpc_flavor cl_flvr_mgc; /* fixed flavor of mgc->mgs */ |
| 255 | |
| 256 | /* the grant values are protected by loi_list_lock below */ |
| 257 | long cl_dirty; /* all _dirty_ in bytes */ |
| 258 | long cl_dirty_max; /* allowed w/o rpc */ |
| 259 | long cl_dirty_transit; /* dirty synchronous */ |
| 260 | long cl_avail_grant; /* bytes of credit for ost */ |
| 261 | long cl_lost_grant; /* lost credits (trunc) */ |
| 262 | |
| 263 | /* since we allocate grant by blocks, we don't know how many grant will |
| 264 | * be used to add a page into cache. As a solution, we reserve maximum |
| 265 | * grant before trying to dirty a page and unreserve the rest. |
Oleg Drokin | c56e256 | 2016-02-24 22:00:25 -0500 | [diff] [blame] | 266 | * See osc_{reserve|unreserve}_grant for details. |
| 267 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 268 | long cl_reserved_grant; |
Hugues Morisset | 498374f | 2014-09-09 16:36:25 +0200 | [diff] [blame] | 269 | struct list_head cl_cache_waiters; /* waiting for cache/grant */ |
| 270 | unsigned long cl_next_shrink_grant; /* jiffies */ |
| 271 | struct list_head cl_grant_shrink_list; /* Timeout event list */ |
| 272 | int cl_grant_shrink_interval; /* seconds */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 273 | |
| 274 | /* A chunk is an optimal size used by osc_extent to determine |
Kirill A. Shutemov | ea1754a | 2016-04-01 15:29:48 +0300 | [diff] [blame] | 275 | * the extent size. A chunk is max(PAGE_SIZE, OST block size) |
Oleg Drokin | c56e256 | 2016-02-24 22:00:25 -0500 | [diff] [blame] | 276 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 277 | int cl_chunkbits; |
| 278 | int cl_chunk; |
| 279 | int cl_extent_tax; /* extent overhead, by bytes */ |
| 280 | |
| 281 | /* keep track of objects that have lois that contain pages which |
| 282 | * have been queued for async brw. this lock also protects the |
Oleg Drokin | c56e256 | 2016-02-24 22:00:25 -0500 | [diff] [blame] | 283 | * lists of osc_client_pages that hang off of the loi |
| 284 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 285 | /* |
| 286 | * ->cl_loi_list_lock protects consistency of |
| 287 | * ->cl_loi_{ready,read,write}_list. ->ap_make_ready() and |
| 288 | * ->ap_completion() call-backs are executed under this lock. As we |
| 289 | * cannot guarantee that these call-backs never block on all platforms |
| 290 | * (as a matter of fact they do block on Mac OS X), type of |
| 291 | * ->cl_loi_list_lock is platform dependent: it's a spin-lock on Linux |
| 292 | * and blocking mutex on Mac OS X. (Alternative is to make this lock |
| 293 | * blocking everywhere, but we don't want to slow down fast-path of |
| 294 | * our main platform.) |
| 295 | * |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 296 | * NB by Jinshan: though field names are still _loi_, but actually |
| 297 | * osc_object{}s are in the list. |
| 298 | */ |
John L. Hammond | 7d53d8f | 2016-03-30 19:48:36 -0400 | [diff] [blame] | 299 | spinlock_t cl_loi_list_lock; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 300 | struct list_head cl_loi_ready_list; |
| 301 | struct list_head cl_loi_hp_ready_list; |
| 302 | struct list_head cl_loi_write_list; |
| 303 | struct list_head cl_loi_read_list; |
| 304 | int cl_r_in_flight; |
| 305 | int cl_w_in_flight; |
Oleg Drokin | 406c1c7 | 2016-02-16 00:46:34 -0500 | [diff] [blame] | 306 | /* just a sum of the loi/lop pending numbers to be exported by sysfs */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 307 | atomic_t cl_pending_w_pages; |
| 308 | atomic_t cl_pending_r_pages; |
| 309 | __u32 cl_max_pages_per_rpc; |
| 310 | int cl_max_rpcs_in_flight; |
| 311 | struct obd_histogram cl_read_rpc_hist; |
| 312 | struct obd_histogram cl_write_rpc_hist; |
| 313 | struct obd_histogram cl_read_page_hist; |
| 314 | struct obd_histogram cl_write_page_hist; |
| 315 | struct obd_histogram cl_read_offset_hist; |
| 316 | struct obd_histogram cl_write_offset_hist; |
| 317 | |
| 318 | /* lru for osc caching pages */ |
| 319 | struct cl_client_cache *cl_cache; |
Hugues Morisset | 498374f | 2014-09-09 16:36:25 +0200 | [diff] [blame] | 320 | struct list_head cl_lru_osc; /* member of cl_cache->ccc_lru */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 321 | atomic_t *cl_lru_left; |
| 322 | atomic_t cl_lru_busy; |
| 323 | atomic_t cl_lru_shrinkers; |
| 324 | atomic_t cl_lru_in_list; |
Hugues Morisset | 498374f | 2014-09-09 16:36:25 +0200 | [diff] [blame] | 325 | struct list_head cl_lru_list; /* lru page list */ |
John L. Hammond | 7d53d8f | 2016-03-30 19:48:36 -0400 | [diff] [blame] | 326 | spinlock_t cl_lru_list_lock; /* page list protector */ |
Prakash Surya | dece0b9 | 2016-04-27 18:21:05 -0400 | [diff] [blame] | 327 | atomic_t cl_unstable_count; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 328 | |
| 329 | /* number of in flight destroy rpcs is limited to max_rpcs_in_flight */ |
| 330 | atomic_t cl_destroy_in_flight; |
| 331 | wait_queue_head_t cl_destroy_waitq; |
| 332 | |
| 333 | struct mdc_rpc_lock *cl_rpc_lock; |
| 334 | struct mdc_rpc_lock *cl_close_lock; |
| 335 | |
| 336 | /* mgc datastruct */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 337 | atomic_t cl_mgc_refcount; |
| 338 | struct obd_export *cl_mgc_mgsexp; |
| 339 | |
| 340 | /* checksumming for data sent over the network */ |
| 341 | unsigned int cl_checksum:1; /* 0 = disabled, 1 = enabled */ |
| 342 | /* supported checksum types that are worked out at connect time */ |
| 343 | __u32 cl_supp_cksum_types; |
| 344 | /* checksum algorithm to be used */ |
Oleg Drokin | d133210 | 2016-02-24 21:59:48 -0500 | [diff] [blame] | 345 | enum cksum_type cl_cksum_type; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 346 | |
| 347 | /* also protected by the poorly named _loi_list_lock lock above */ |
| 348 | struct osc_async_rc cl_ar; |
| 349 | |
| 350 | /* used by quotacheck when the servers are older than 2.4 */ |
| 351 | int cl_qchk_stat; /* quotacheck stat of the peer */ |
| 352 | #define CL_NOT_QUOTACHECKED 1 /* client->cl_qchk_stat init value */ |
| 353 | #if LUSTRE_VERSION_CODE >= OBD_OCD_VERSION(2, 7, 50, 0) |
| 354 | #warning "please consider removing quotacheck compatibility code" |
| 355 | #endif |
| 356 | |
| 357 | /* sequence manager */ |
| 358 | struct lu_client_seq *cl_seq; |
| 359 | |
| 360 | atomic_t cl_resends; /* resend count */ |
| 361 | |
| 362 | /* ptlrpc work for writeback in ptlrpcd context */ |
| 363 | void *cl_writeback_work; |
Jinshan Xiong | 2579d8d | 2016-03-30 19:48:27 -0400 | [diff] [blame] | 364 | void *cl_lru_work; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 365 | /* hash tables for osc_quota_info */ |
Lisa Nguyen | 6da6eab | 2013-10-21 18:16:26 -0700 | [diff] [blame] | 366 | struct cfs_hash *cl_quota_hash[MAXQUOTAS]; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 367 | }; |
Mike Rapoport | c9f6bb9 | 2015-10-13 16:03:42 +0300 | [diff] [blame] | 368 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 369 | #define obd2cli_tgt(obd) ((char *)(obd)->u.cli.cl_target_uuid.uuid) |
| 370 | |
| 371 | struct obd_id_info { |
| 372 | __u32 idx; |
Oleg Drokin | 21aef7d | 2014-08-15 12:55:56 -0400 | [diff] [blame] | 373 | u64 *data; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 374 | }; |
| 375 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 376 | struct echo_client_obd { |
| 377 | struct obd_export *ec_exp; /* the local connection to osc/lov */ |
| 378 | spinlock_t ec_lock; |
| 379 | struct list_head ec_objects; |
| 380 | struct list_head ec_locks; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 381 | __u64 ec_unique; |
| 382 | }; |
| 383 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 384 | /* Generic subset of OSTs */ |
| 385 | struct ost_pool { |
Oleg Drokin | c56e256 | 2016-02-24 22:00:25 -0500 | [diff] [blame] | 386 | __u32 *op_array; /* array of index of lov_obd->lov_tgts */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 387 | unsigned int op_count; /* number of OSTs in the array */ |
| 388 | unsigned int op_size; /* allocated size of lp_array */ |
| 389 | struct rw_semaphore op_rw_sem; /* to protect ost_pool use */ |
| 390 | }; |
| 391 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 392 | /* allow statfs data caching for 1 second */ |
| 393 | #define OBD_STATFS_CACHE_SECONDS 1 |
| 394 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 395 | struct lov_tgt_desc { |
| 396 | struct list_head ltd_kill; |
| 397 | struct obd_uuid ltd_uuid; |
| 398 | struct obd_device *ltd_obd; |
| 399 | struct obd_export *ltd_exp; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 400 | __u32 ltd_gen; |
| 401 | __u32 ltd_index; /* index in lov_obd->tgts */ |
| 402 | unsigned long ltd_active:1,/* is this target up for requests */ |
| 403 | ltd_activate:1,/* should target be activated */ |
| 404 | ltd_reap:1; /* should this target be deleted */ |
| 405 | }; |
| 406 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 407 | struct lov_obd { |
| 408 | struct lov_desc desc; |
| 409 | struct lov_tgt_desc **lov_tgts; /* sparse array */ |
Oleg Drokin | c56e256 | 2016-02-24 22:00:25 -0500 | [diff] [blame] | 410 | struct ost_pool lov_packed; /* all OSTs in a packed array */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 411 | struct mutex lov_lock; |
| 412 | struct obd_connect_data lov_ocd; |
| 413 | atomic_t lov_refcount; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 414 | __u32 lov_death_row;/* tgts scheduled to be deleted */ |
| 415 | __u32 lov_tgt_size; /* size of tgts array */ |
| 416 | int lov_connects; |
| 417 | int lov_pool_count; |
Lisa Nguyen | 6da6eab | 2013-10-21 18:16:26 -0700 | [diff] [blame] | 418 | struct cfs_hash *lov_pools_hash_body; /* used for key access */ |
Hugues Morisset | 498374f | 2014-09-09 16:36:25 +0200 | [diff] [blame] | 419 | struct list_head lov_pool_list; /* used for sequential access */ |
Dmitry Eremin | 61e87ab | 2015-05-21 15:32:27 -0400 | [diff] [blame] | 420 | struct dentry *lov_pool_debugfs_entry; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 421 | enum lustre_sec_part lov_sp_me; |
| 422 | |
Prakash Surya | ac5b148 | 2016-04-27 18:21:04 -0400 | [diff] [blame] | 423 | /* Cached LRU and unstable data from upper layer */ |
Emoly Liu | 1b02bde | 2016-06-20 16:55:24 -0400 | [diff] [blame] | 424 | struct cl_client_cache *lov_cache; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 425 | |
| 426 | struct rw_semaphore lov_notify_lock; |
Oleg Drokin | cb1debf | 2015-05-21 15:32:22 -0400 | [diff] [blame] | 427 | |
| 428 | struct kobject *lov_tgts_kobj; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 429 | }; |
| 430 | |
| 431 | struct lmv_tgt_desc { |
| 432 | struct obd_uuid ltd_uuid; |
| 433 | struct obd_export *ltd_exp; |
| 434 | int ltd_idx; |
| 435 | struct mutex ltd_fid_mutex; |
| 436 | unsigned long ltd_active:1; /* target up for requests */ |
| 437 | }; |
| 438 | |
| 439 | enum placement_policy { |
| 440 | PLACEMENT_CHAR_POLICY = 0, |
| 441 | PLACEMENT_NID_POLICY = 1, |
| 442 | PLACEMENT_INVAL_POLICY = 2, |
| 443 | PLACEMENT_MAX_POLICY |
| 444 | }; |
| 445 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 446 | struct lmv_obd { |
| 447 | int refcount; |
| 448 | struct lu_client_fld lmv_fld; |
| 449 | spinlock_t lmv_lock; |
Hugues Morisset | fe67299 | 2014-09-09 16:36:26 +0200 | [diff] [blame] | 450 | enum placement_policy lmv_placement; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 451 | struct lmv_desc desc; |
| 452 | struct obd_uuid cluuid; |
| 453 | struct obd_export *exp; |
| 454 | |
John L. Hammond | 019e935 | 2016-03-30 19:48:35 -0400 | [diff] [blame] | 455 | struct mutex lmv_init_mutex; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 456 | int connected; |
| 457 | int max_easize; |
| 458 | int max_def_easize; |
| 459 | int max_cookiesize; |
Brian Behlendorf | 4477934 | 2014-04-27 13:06:47 -0400 | [diff] [blame] | 460 | int max_def_cookiesize; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 461 | int server_timeout; |
| 462 | |
| 463 | int tgts_size; /* size of tgts array */ |
| 464 | struct lmv_tgt_desc **tgts; |
| 465 | |
| 466 | struct obd_connect_data conn_data; |
Oleg Drokin | b5fa70d | 2015-05-21 15:32:23 -0400 | [diff] [blame] | 467 | struct kobject *lmv_tgts_kobj; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 468 | }; |
| 469 | |
| 470 | struct niobuf_local { |
| 471 | __u64 lnb_file_offset; |
| 472 | __u32 lnb_page_offset; |
| 473 | __u32 len; |
| 474 | __u32 flags; |
| 475 | struct page *page; |
| 476 | struct dentry *dentry; |
| 477 | int lnb_grant_used; |
| 478 | int rc; |
| 479 | }; |
| 480 | |
| 481 | #define LUSTRE_FLD_NAME "fld" |
| 482 | #define LUSTRE_SEQ_NAME "seq" |
| 483 | |
| 484 | #define LUSTRE_MDD_NAME "mdd" |
| 485 | #define LUSTRE_OSD_LDISKFS_NAME "osd-ldiskfs" |
| 486 | #define LUSTRE_OSD_ZFS_NAME "osd-zfs" |
| 487 | #define LUSTRE_VVP_NAME "vvp" |
| 488 | #define LUSTRE_LMV_NAME "lmv" |
| 489 | #define LUSTRE_SLP_NAME "slp" |
| 490 | #define LUSTRE_LOD_NAME "lod" |
| 491 | #define LUSTRE_OSP_NAME "osp" |
| 492 | #define LUSTRE_LWP_NAME "lwp" |
| 493 | |
| 494 | /* obd device type names */ |
| 495 | /* FIXME all the references to LUSTRE_MDS_NAME should be swapped with LUSTRE_MDT_NAME */ |
| 496 | #define LUSTRE_MDS_NAME "mds" |
| 497 | #define LUSTRE_MDT_NAME "mdt" |
| 498 | #define LUSTRE_MDC_NAME "mdc" |
| 499 | #define LUSTRE_OSS_NAME "ost" /* FIXME change name to oss */ |
| 500 | #define LUSTRE_OST_NAME "obdfilter" /* FIXME change name to ost */ |
| 501 | #define LUSTRE_OSC_NAME "osc" |
| 502 | #define LUSTRE_LOV_NAME "lov" |
| 503 | #define LUSTRE_MGS_NAME "mgs" |
| 504 | #define LUSTRE_MGC_NAME "mgc" |
| 505 | |
| 506 | #define LUSTRE_ECHO_NAME "obdecho" |
| 507 | #define LUSTRE_ECHO_CLIENT_NAME "echo_client" |
| 508 | #define LUSTRE_QMT_NAME "qmt" |
| 509 | |
| 510 | /* Constant obd names (post-rename) */ |
| 511 | #define LUSTRE_MDS_OBDNAME "MDS" |
| 512 | #define LUSTRE_OSS_OBDNAME "OSS" |
| 513 | #define LUSTRE_MGS_OBDNAME "MGS" |
| 514 | #define LUSTRE_MGC_OBDNAME "MGC" |
| 515 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 516 | /* Don't conflict with on-wire flags OBD_BRW_WRITE, etc */ |
| 517 | #define N_LOCAL_TEMP_PAGE 0x10000000 |
| 518 | |
| 519 | struct obd_trans_info { |
| 520 | __u64 oti_transno; |
| 521 | __u64 oti_xid; |
| 522 | /* Only used on the server side for tracking acks. */ |
| 523 | struct oti_req_ack_lock { |
| 524 | struct lustre_handle lock; |
| 525 | __u32 mode; |
| 526 | } oti_ack_locks[4]; |
| 527 | void *oti_handle; |
| 528 | struct llog_cookie oti_onecookie; |
| 529 | struct llog_cookie *oti_logcookies; |
| 530 | int oti_numcookies; |
| 531 | /** synchronous write is needed */ |
| 532 | unsigned long oti_sync_write:1; |
| 533 | |
| 534 | /* initial thread handling transaction */ |
Hugues Morisset | 498374f | 2014-09-09 16:36:25 +0200 | [diff] [blame] | 535 | struct ptlrpc_thread *oti_thread; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 536 | __u32 oti_conn_cnt; |
| 537 | /** VBR: versions */ |
| 538 | __u64 oti_pre_version; |
| 539 | /** JobID */ |
| 540 | char *oti_jobid; |
| 541 | |
| 542 | struct obd_uuid *oti_ost_uuid; |
| 543 | }; |
| 544 | |
Greg Donald | 1d8cb70 | 2014-08-25 20:07:19 -0500 | [diff] [blame] | 545 | static inline void oti_alloc_cookies(struct obd_trans_info *oti, |
| 546 | int num_cookies) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 547 | { |
| 548 | if (!oti) |
| 549 | return; |
| 550 | |
| 551 | if (num_cookies == 1) |
| 552 | oti->oti_logcookies = &oti->oti_onecookie; |
| 553 | else |
Oleg Drokin | df29ca2 | 2015-09-16 12:27:02 -0400 | [diff] [blame] | 554 | oti->oti_logcookies = libcfs_kvzalloc(num_cookies * sizeof(oti->oti_onecookie), |
| 555 | GFP_NOFS); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 556 | |
| 557 | oti->oti_numcookies = num_cookies; |
| 558 | } |
| 559 | |
| 560 | static inline void oti_free_cookies(struct obd_trans_info *oti) |
| 561 | { |
| 562 | if (!oti || !oti->oti_logcookies) |
| 563 | return; |
| 564 | |
| 565 | if (oti->oti_logcookies == &oti->oti_onecookie) |
| 566 | LASSERT(oti->oti_numcookies == 1); |
| 567 | else |
Oleg Drokin | df29ca2 | 2015-09-16 12:27:02 -0400 | [diff] [blame] | 568 | kvfree(oti->oti_logcookies); |
| 569 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 570 | oti->oti_logcookies = NULL; |
| 571 | oti->oti_numcookies = 0; |
| 572 | } |
| 573 | |
| 574 | /* |
| 575 | * Events signalled through obd_notify() upcall-chain. |
| 576 | */ |
| 577 | enum obd_notify_event { |
| 578 | /* target added */ |
| 579 | OBD_NOTIFY_CREATE, |
| 580 | /* Device connect start */ |
| 581 | OBD_NOTIFY_CONNECT, |
| 582 | /* Device activated */ |
| 583 | OBD_NOTIFY_ACTIVE, |
| 584 | /* Device deactivated */ |
| 585 | OBD_NOTIFY_INACTIVE, |
| 586 | /* Device disconnected */ |
| 587 | OBD_NOTIFY_DISCON, |
| 588 | /* Connect data for import were changed */ |
| 589 | OBD_NOTIFY_OCD, |
| 590 | /* Sync request */ |
| 591 | OBD_NOTIFY_SYNC_NONBLOCK, |
| 592 | OBD_NOTIFY_SYNC, |
| 593 | /* Configuration event */ |
| 594 | OBD_NOTIFY_CONFIG, |
| 595 | /* Administratively deactivate/activate event */ |
| 596 | OBD_NOTIFY_DEACTIVATE, |
| 597 | OBD_NOTIFY_ACTIVATE |
| 598 | }; |
| 599 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 600 | /* |
| 601 | * Data structure used to pass obd_notify()-event to non-obd listeners (llite |
Oleg Drokin | 85f552d | 2016-02-26 01:49:56 -0500 | [diff] [blame] | 602 | * being main example). |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 603 | */ |
| 604 | struct obd_notify_upcall { |
| 605 | int (*onu_upcall)(struct obd_device *host, struct obd_device *watched, |
| 606 | enum obd_notify_event ev, void *owner, void *data); |
| 607 | /* Opaque datum supplied by upper layer listener */ |
| 608 | void *onu_owner; |
| 609 | }; |
| 610 | |
| 611 | struct target_recovery_data { |
| 612 | svc_handler_t trd_recovery_handler; |
| 613 | pid_t trd_processing_task; |
| 614 | struct completion trd_starting; |
| 615 | struct completion trd_finishing; |
| 616 | }; |
| 617 | |
| 618 | struct obd_llog_group { |
| 619 | int olg_seq; |
| 620 | struct llog_ctxt *olg_ctxts[LLOG_MAX_CTXTS]; |
| 621 | wait_queue_head_t olg_waitq; |
| 622 | spinlock_t olg_lock; |
| 623 | struct mutex olg_cat_processing; |
| 624 | }; |
| 625 | |
| 626 | /* corresponds to one of the obd's */ |
| 627 | #define OBD_DEVICE_MAGIC 0XAB5CD6EF |
| 628 | #define OBD_DEV_BY_DEVNAME 0xffffd0de |
| 629 | |
John L. Hammond | 91b3aaf | 2014-09-09 13:39:08 -0500 | [diff] [blame] | 630 | struct lvfs_run_ctxt { |
| 631 | struct dt_device *dt; |
| 632 | }; |
| 633 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 634 | struct obd_device { |
| 635 | struct obd_type *obd_type; |
| 636 | __u32 obd_magic; |
| 637 | |
| 638 | /* common and UUID name of this device */ |
| 639 | char obd_name[MAX_OBD_NAME]; |
| 640 | struct obd_uuid obd_uuid; |
| 641 | |
| 642 | struct lu_device *obd_lu_dev; |
| 643 | |
| 644 | int obd_minor; |
| 645 | /* bitfield modification is protected by obd_dev_lock */ |
| 646 | unsigned long obd_attached:1, /* finished attach */ |
| 647 | obd_set_up:1, /* finished setup */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 648 | obd_version_recov:1, /* obd uses version checking */ |
Oleg Drokin | c56e256 | 2016-02-24 22:00:25 -0500 | [diff] [blame] | 649 | obd_replayable:1,/* recovery is enabled; inform clients */ |
| 650 | obd_no_transno:1, /* no committed-transno notification */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 651 | obd_no_recov:1, /* fail instead of retry messages */ |
| 652 | obd_stopping:1, /* started cleanup */ |
| 653 | obd_starting:1, /* started setup */ |
| 654 | obd_force:1, /* cleanup with > 0 obd refcount */ |
Oleg Drokin | c56e256 | 2016-02-24 22:00:25 -0500 | [diff] [blame] | 655 | obd_fail:1, /* cleanup with failover */ |
| 656 | obd_async_recov:1, /* allow asynchronous orphan cleanup */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 657 | obd_no_conn:1, /* deny new connections */ |
| 658 | obd_inactive:1, /* device active/inactive |
Oleg Drokin | 406c1c7 | 2016-02-16 00:46:34 -0500 | [diff] [blame] | 659 | * (for sysfs status only!!) |
| 660 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 661 | obd_no_ir:1, /* no imperative recovery. */ |
| 662 | obd_process_conf:1; /* device is processing mgs config */ |
| 663 | /* use separate field as it is set in interrupt to don't mess with |
Oleg Drokin | c56e256 | 2016-02-24 22:00:25 -0500 | [diff] [blame] | 664 | * protection of other bits using _bh lock |
| 665 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 666 | unsigned long obd_recovery_expired:1; |
| 667 | /* uuid-export hash body */ |
Lisa Nguyen | 6da6eab | 2013-10-21 18:16:26 -0700 | [diff] [blame] | 668 | struct cfs_hash *obd_uuid_hash; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 669 | atomic_t obd_refcount; |
| 670 | wait_queue_head_t obd_refcount_waitq; |
| 671 | struct list_head obd_exports; |
| 672 | struct list_head obd_unlinked_exports; |
| 673 | struct list_head obd_delayed_exports; |
| 674 | int obd_num_exports; |
| 675 | spinlock_t obd_nid_lock; |
| 676 | struct ldlm_namespace *obd_namespace; |
| 677 | struct ptlrpc_client obd_ldlm_client; /* XXX OST/MDS only */ |
| 678 | /* a spinlock is OK for what we do now, may need a semaphore later */ |
| 679 | spinlock_t obd_dev_lock; /* protect OBD bitfield above */ |
| 680 | struct mutex obd_dev_mutex; |
| 681 | __u64 obd_last_committed; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 682 | spinlock_t obd_osfs_lock; |
| 683 | struct obd_statfs obd_osfs; /* locked by obd_osfs_lock */ |
| 684 | __u64 obd_osfs_age; |
| 685 | struct lvfs_run_ctxt obd_lvfs_ctxt; |
| 686 | struct obd_llog_group obd_olg; /* default llog group */ |
| 687 | struct obd_device *obd_observer; |
| 688 | struct rw_semaphore obd_observer_link_sem; |
| 689 | struct obd_notify_upcall obd_upcall; |
| 690 | struct obd_export *obd_self_export; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 691 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 692 | union { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 693 | struct client_obd cli; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 694 | struct echo_client_obd echo_client; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 695 | struct lov_obd lov; |
| 696 | struct lmv_obd lmv; |
| 697 | } u; |
| 698 | /* Fields used by LProcFS */ |
| 699 | unsigned int obd_cntr_base; |
| 700 | struct lprocfs_stats *obd_stats; |
| 701 | |
| 702 | unsigned int md_cntr_base; |
| 703 | struct lprocfs_stats *md_stats; |
| 704 | |
Dmitry Eremin | 61e87ab | 2015-05-21 15:32:27 -0400 | [diff] [blame] | 705 | struct dentry *obd_debugfs_entry; |
Dmitry Eremin | 61e87ab | 2015-05-21 15:32:27 -0400 | [diff] [blame] | 706 | struct dentry *obd_svc_debugfs_entry; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 707 | struct lprocfs_stats *obd_svc_stats; |
| 708 | atomic_t obd_evict_inprogress; |
| 709 | wait_queue_head_t obd_evict_inprogress_waitq; |
Hugues Morisset | 498374f | 2014-09-09 16:36:25 +0200 | [diff] [blame] | 710 | struct list_head obd_evict_list; /* protected with pet_lock */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 711 | |
| 712 | /** |
| 713 | * Ldlm pool part. Save last calculated SLV and Limit. |
| 714 | */ |
| 715 | rwlock_t obd_pool_lock; |
| 716 | int obd_pool_limit; |
| 717 | __u64 obd_pool_slv; |
| 718 | |
| 719 | /** |
| 720 | * A list of outstanding class_incref()'s against this obd. For |
| 721 | * debugging. |
| 722 | */ |
| 723 | struct lu_ref obd_reference; |
| 724 | |
| 725 | int obd_conn_inprogress; |
Oleg Drokin | 9b80130 | 2015-05-21 15:32:16 -0400 | [diff] [blame] | 726 | |
| 727 | struct kobject obd_kobj; /* sysfs object */ |
| 728 | struct completion obd_kobj_unregister; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 729 | }; |
| 730 | |
| 731 | #define OBD_LLOG_FL_SENDNOW 0x0001 |
| 732 | #define OBD_LLOG_FL_EXIT 0x0002 |
| 733 | |
| 734 | enum obd_cleanup_stage { |
| 735 | /* Special case hack for MDS LOVs */ |
| 736 | OBD_CLEANUP_EARLY, |
| 737 | /* can be directly mapped to .ldto_device_fini() */ |
| 738 | OBD_CLEANUP_EXPORTS, |
| 739 | }; |
| 740 | |
| 741 | /* get/set_info keys */ |
| 742 | #define KEY_ASYNC "async" |
| 743 | #define KEY_BLOCKSIZE_BITS "blocksize_bits" |
| 744 | #define KEY_BLOCKSIZE "blocksize" |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 745 | #define KEY_CHANGELOG_CLEAR "changelog_clear" |
| 746 | #define KEY_FID2PATH "fid2path" |
| 747 | #define KEY_CHECKSUM "checksum" |
| 748 | #define KEY_CLEAR_FS "clear_fs" |
| 749 | #define KEY_CONN_DATA "conn_data" |
| 750 | #define KEY_EVICT_BY_NID "evict_by_nid" |
| 751 | #define KEY_FIEMAP "fiemap" |
| 752 | #define KEY_FLUSH_CTX "flush_ctx" |
| 753 | #define KEY_GRANT_SHRINK "grant_shrink" |
| 754 | #define KEY_HSM_COPYTOOL_SEND "hsm_send" |
| 755 | #define KEY_INIT_RECOV_BACKUP "init_recov_bk" |
| 756 | #define KEY_INIT_RECOV "initial_recov" |
| 757 | #define KEY_INTERMDS "inter_mds" |
| 758 | #define KEY_LAST_ID "last_id" |
| 759 | #define KEY_LAST_FID "last_fid" |
| 760 | #define KEY_LOCK_TO_STRIPE "lock_to_stripe" |
| 761 | #define KEY_LOVDESC "lovdesc" |
| 762 | #define KEY_LOV_IDX "lov_idx" |
Brian Behlendorf | 4477934 | 2014-04-27 13:06:47 -0400 | [diff] [blame] | 763 | #define KEY_MAX_EASIZE "max_easize" |
| 764 | #define KEY_DEFAULT_EASIZE "default_easize" |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 765 | #define KEY_MDS_CONN "mds_conn" |
| 766 | #define KEY_MGSSEC "mgssec" |
| 767 | #define KEY_NEXT_ID "next_id" |
| 768 | #define KEY_READ_ONLY "read-only" |
| 769 | #define KEY_REGISTER_TARGET "register_target" |
| 770 | #define KEY_SET_FS "set_fs" |
| 771 | #define KEY_TGT_COUNT "tgt_count" |
| 772 | /* KEY_SET_INFO in lustre_idl.h */ |
| 773 | #define KEY_SPTLRPC_CONF "sptlrpc_conf" |
| 774 | #define KEY_CONNECT_FLAG "connect_flags" |
| 775 | #define KEY_SYNC_LOCK_CANCEL "sync_lock_cancel" |
| 776 | |
| 777 | #define KEY_CACHE_SET "cache_set" |
| 778 | #define KEY_CACHE_LRU_SHRINK "cache_lru_shrink" |
| 779 | #define KEY_CHANGELOG_INDEX "changelog_index" |
| 780 | |
| 781 | struct lu_context; |
| 782 | |
| 783 | /* /!\ must be coherent with include/linux/namei.h on patched kernel */ |
| 784 | #define IT_OPEN (1 << 0) |
| 785 | #define IT_CREAT (1 << 1) |
| 786 | #define IT_READDIR (1 << 2) |
| 787 | #define IT_GETATTR (1 << 3) |
| 788 | #define IT_LOOKUP (1 << 4) |
| 789 | #define IT_UNLINK (1 << 5) |
| 790 | #define IT_TRUNC (1 << 6) |
| 791 | #define IT_GETXATTR (1 << 7) |
| 792 | #define IT_EXEC (1 << 8) |
| 793 | #define IT_PIN (1 << 9) |
| 794 | #define IT_LAYOUT (1 << 10) |
| 795 | #define IT_QUOTA_DQACQ (1 << 11) |
| 796 | #define IT_QUOTA_CONN (1 << 12) |
Andrew Perepechko | 7fc1f83 | 2013-12-03 21:58:49 +0800 | [diff] [blame] | 797 | #define IT_SETXATTR (1 << 13) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 798 | |
| 799 | static inline int it_to_lock_mode(struct lookup_intent *it) |
| 800 | { |
| 801 | /* CREAT needs to be tested before open (both could be set) */ |
| 802 | if (it->it_op & IT_CREAT) |
| 803 | return LCK_CW; |
| 804 | else if (it->it_op & (IT_READDIR | IT_GETATTR | IT_OPEN | IT_LOOKUP | |
| 805 | IT_LAYOUT)) |
| 806 | return LCK_CR; |
Andrew Perepechko | 7fc1f83 | 2013-12-03 21:58:49 +0800 | [diff] [blame] | 807 | else if (it->it_op & IT_GETXATTR) |
| 808 | return LCK_PR; |
| 809 | else if (it->it_op & IT_SETXATTR) |
| 810 | return LCK_PW; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 811 | |
| 812 | LASSERTF(0, "Invalid it_op: %d\n", it->it_op); |
| 813 | return -EINVAL; |
| 814 | } |
| 815 | |
| 816 | struct md_op_data { |
Masanari Iida | 1789118 | 2014-03-08 22:58:33 +0900 | [diff] [blame] | 817 | struct lu_fid op_fid1; /* operation fid1 (usually parent) */ |
| 818 | struct lu_fid op_fid2; /* operation fid2 (usually child) */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 819 | struct lu_fid op_fid3; /* 2 extra fids to find conflicting */ |
| 820 | struct lu_fid op_fid4; /* to the operation locks. */ |
Oleg Drokin | 114acca | 2014-08-15 12:55:55 -0400 | [diff] [blame] | 821 | u32 op_mds; /* what mds server open will go to */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 822 | struct lustre_handle op_handle; |
Oleg Drokin | 21aef7d | 2014-08-15 12:55:56 -0400 | [diff] [blame] | 823 | s64 op_mod_time; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 824 | const char *op_name; |
| 825 | int op_namelen; |
| 826 | __u32 op_mode; |
| 827 | struct lmv_stripe_md *op_mea1; |
| 828 | struct lmv_stripe_md *op_mea2; |
| 829 | __u32 op_suppgids[2]; |
| 830 | __u32 op_fsuid; |
| 831 | __u32 op_fsgid; |
| 832 | cfs_cap_t op_cap; |
| 833 | void *op_data; |
| 834 | |
| 835 | /* iattr fields and blocks. */ |
| 836 | struct iattr op_attr; |
| 837 | unsigned int op_attr_flags; |
| 838 | __u64 op_valid; |
| 839 | loff_t op_attr_blocks; |
| 840 | |
| 841 | /* Size-on-MDS epoch and flags. */ |
| 842 | __u64 op_ioepoch; |
| 843 | __u32 op_flags; |
| 844 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 845 | /* Various operation flags. */ |
Jinshan Xiong | 48d23e6 | 2013-12-03 21:58:48 +0800 | [diff] [blame] | 846 | enum mds_op_bias op_bias; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 847 | |
| 848 | /* Operation type */ |
| 849 | __u32 op_opc; |
| 850 | |
| 851 | /* Used by readdir */ |
| 852 | __u64 op_offset; |
| 853 | |
| 854 | /* Used by readdir */ |
| 855 | __u32 op_npages; |
| 856 | |
| 857 | /* used to transfer info between the stacks of MD client |
Oleg Drokin | c56e256 | 2016-02-24 22:00:25 -0500 | [diff] [blame] | 858 | * see enum op_cli_flags |
| 859 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 860 | __u32 op_cli_flags; |
Jinshan Xiong | 48d23e6 | 2013-12-03 21:58:48 +0800 | [diff] [blame] | 861 | |
| 862 | /* File object data version for HSM release, on client */ |
| 863 | __u64 op_data_version; |
| 864 | struct lustre_handle op_lease_handle; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 865 | }; |
| 866 | |
| 867 | enum op_cli_flags { |
| 868 | CLI_SET_MEA = 1 << 0, |
| 869 | CLI_RM_ENTRY = 1 << 1, |
| 870 | }; |
| 871 | |
| 872 | struct md_enqueue_info; |
| 873 | /* metadata stat-ahead */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 874 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 875 | struct md_enqueue_info { |
| 876 | struct md_op_data mi_data; |
| 877 | struct lookup_intent mi_it; |
| 878 | struct lustre_handle mi_lockh; |
| 879 | struct inode *mi_dir; |
Hugues Morisset | fe67299 | 2014-09-09 16:36:26 +0200 | [diff] [blame] | 880 | int (*mi_cb)(struct ptlrpc_request *req, |
Oleg Drokin | 10457d4 | 2016-02-26 01:49:50 -0500 | [diff] [blame] | 881 | struct md_enqueue_info *minfo, int rc); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 882 | __u64 mi_cbdata; |
| 883 | unsigned int mi_generation; |
| 884 | }; |
| 885 | |
| 886 | struct obd_ops { |
Dan Carpenter | a13b1f3 | 2015-10-29 12:24:40 +0300 | [diff] [blame] | 887 | struct module *owner; |
| 888 | int (*iocontrol)(unsigned int cmd, struct obd_export *exp, int len, |
Oleg Drokin | e09bee3 | 2016-01-03 12:05:43 -0500 | [diff] [blame] | 889 | void *karg, void __user *uarg); |
Dan Carpenter | a13b1f3 | 2015-10-29 12:24:40 +0300 | [diff] [blame] | 890 | int (*get_info)(const struct lu_env *env, struct obd_export *, |
| 891 | __u32 keylen, void *key, __u32 *vallen, void *val, |
| 892 | struct lov_stripe_md *lsm); |
| 893 | int (*set_info_async)(const struct lu_env *, struct obd_export *, |
| 894 | __u32 keylen, void *key, |
| 895 | __u32 vallen, void *val, |
| 896 | struct ptlrpc_request_set *set); |
| 897 | int (*attach)(struct obd_device *dev, u32 len, void *data); |
| 898 | int (*detach)(struct obd_device *dev); |
| 899 | int (*setup)(struct obd_device *dev, struct lustre_cfg *cfg); |
| 900 | int (*precleanup)(struct obd_device *dev, |
| 901 | enum obd_cleanup_stage cleanup_stage); |
| 902 | int (*cleanup)(struct obd_device *dev); |
| 903 | int (*process_config)(struct obd_device *dev, u32 len, void *data); |
| 904 | int (*postrecov)(struct obd_device *dev); |
| 905 | int (*add_conn)(struct obd_import *imp, struct obd_uuid *uuid, |
| 906 | int priority); |
| 907 | int (*del_conn)(struct obd_import *imp, struct obd_uuid *uuid); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 908 | /* connect to the target device with given connection |
| 909 | * data. @ocd->ocd_connect_flags is modified to reflect flags actually |
| 910 | * granted by the target, which are guaranteed to be a subset of flags |
Oleg Drokin | c56e256 | 2016-02-24 22:00:25 -0500 | [diff] [blame] | 911 | * asked for. If @ocd == NULL, use default parameters. |
| 912 | */ |
Dan Carpenter | a13b1f3 | 2015-10-29 12:24:40 +0300 | [diff] [blame] | 913 | int (*connect)(const struct lu_env *env, |
| 914 | struct obd_export **exp, struct obd_device *src, |
| 915 | struct obd_uuid *cluuid, struct obd_connect_data *ocd, |
| 916 | void *localdata); |
| 917 | int (*reconnect)(const struct lu_env *env, |
| 918 | struct obd_export *exp, struct obd_device *src, |
| 919 | struct obd_uuid *cluuid, |
| 920 | struct obd_connect_data *ocd, |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 921 | void *localdata); |
Dan Carpenter | a13b1f3 | 2015-10-29 12:24:40 +0300 | [diff] [blame] | 922 | int (*disconnect)(struct obd_export *exp); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 923 | |
| 924 | /* Initialize/finalize fids infrastructure. */ |
Dan Carpenter | a13b1f3 | 2015-10-29 12:24:40 +0300 | [diff] [blame] | 925 | int (*fid_init)(struct obd_device *obd, |
| 926 | struct obd_export *exp, enum lu_cli_type type); |
| 927 | int (*fid_fini)(struct obd_device *obd); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 928 | |
| 929 | /* Allocate new fid according to passed @hint. */ |
Dan Carpenter | a13b1f3 | 2015-10-29 12:24:40 +0300 | [diff] [blame] | 930 | int (*fid_alloc)(struct obd_export *exp, struct lu_fid *fid, |
| 931 | struct md_op_data *op_data); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 932 | |
| 933 | /* |
| 934 | * Object with @fid is getting deleted, we may want to do something |
| 935 | * about this. |
| 936 | */ |
Dan Carpenter | a13b1f3 | 2015-10-29 12:24:40 +0300 | [diff] [blame] | 937 | int (*statfs)(const struct lu_env *, struct obd_export *exp, |
| 938 | struct obd_statfs *osfs, __u64 max_age, __u32 flags); |
| 939 | int (*statfs_async)(struct obd_export *exp, struct obd_info *oinfo, |
| 940 | __u64 max_age, struct ptlrpc_request_set *set); |
| 941 | int (*packmd)(struct obd_export *exp, struct lov_mds_md **disk_tgt, |
| 942 | struct lov_stripe_md *mem_src); |
| 943 | int (*unpackmd)(struct obd_export *exp, |
| 944 | struct lov_stripe_md **mem_tgt, |
| 945 | struct lov_mds_md *disk_src, int disk_len); |
| 946 | int (*preallocate)(struct lustre_handle *, u32 *req, u64 *ids); |
| 947 | int (*create)(const struct lu_env *env, struct obd_export *exp, |
| 948 | struct obdo *oa, struct lov_stripe_md **ea, |
| 949 | struct obd_trans_info *oti); |
| 950 | int (*destroy)(const struct lu_env *env, struct obd_export *exp, |
| 951 | struct obdo *oa, struct lov_stripe_md *ea, |
| 952 | struct obd_trans_info *oti, struct obd_export *md_exp); |
| 953 | int (*setattr)(const struct lu_env *, struct obd_export *exp, |
| 954 | struct obd_info *oinfo, struct obd_trans_info *oti); |
| 955 | int (*setattr_async)(struct obd_export *exp, struct obd_info *oinfo, |
| 956 | struct obd_trans_info *oti, |
| 957 | struct ptlrpc_request_set *rqset); |
| 958 | int (*getattr)(const struct lu_env *env, struct obd_export *exp, |
| 959 | struct obd_info *oinfo); |
| 960 | int (*getattr_async)(struct obd_export *exp, struct obd_info *oinfo, |
| 961 | struct ptlrpc_request_set *set); |
| 962 | int (*adjust_kms)(struct obd_export *exp, struct lov_stripe_md *lsm, |
| 963 | u64 size, int shrink); |
| 964 | int (*preprw)(const struct lu_env *env, int cmd, |
| 965 | struct obd_export *exp, struct obdo *oa, int objcount, |
| 966 | struct obd_ioobj *obj, struct niobuf_remote *remote, |
| 967 | int *nr_pages, struct niobuf_local *local, |
| 968 | struct obd_trans_info *oti); |
| 969 | int (*commitrw)(const struct lu_env *env, int cmd, |
| 970 | struct obd_export *exp, struct obdo *oa, |
| 971 | int objcount, struct obd_ioobj *obj, |
| 972 | struct niobuf_remote *remote, int pages, |
| 973 | struct niobuf_local *local, |
| 974 | struct obd_trans_info *oti, int rc); |
| 975 | int (*find_cbdata)(struct obd_export *, struct lov_stripe_md *, |
| 976 | ldlm_iterator_t it, void *data); |
| 977 | int (*init_export)(struct obd_export *exp); |
| 978 | int (*destroy_export)(struct obd_export *exp); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 979 | |
| 980 | /* metadata-only methods */ |
Dan Carpenter | a13b1f3 | 2015-10-29 12:24:40 +0300 | [diff] [blame] | 981 | int (*import_event)(struct obd_device *, struct obd_import *, |
| 982 | enum obd_import_event); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 983 | |
Dan Carpenter | a13b1f3 | 2015-10-29 12:24:40 +0300 | [diff] [blame] | 984 | int (*notify)(struct obd_device *obd, struct obd_device *watched, |
| 985 | enum obd_notify_event ev, void *data); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 986 | |
Dan Carpenter | a13b1f3 | 2015-10-29 12:24:40 +0300 | [diff] [blame] | 987 | int (*health_check)(const struct lu_env *env, struct obd_device *); |
| 988 | struct obd_uuid *(*get_uuid)(struct obd_export *exp); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 989 | |
| 990 | /* quota methods */ |
Dan Carpenter | a13b1f3 | 2015-10-29 12:24:40 +0300 | [diff] [blame] | 991 | int (*quotacheck)(struct obd_device *, struct obd_export *, |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 992 | struct obd_quotactl *); |
Dan Carpenter | a13b1f3 | 2015-10-29 12:24:40 +0300 | [diff] [blame] | 993 | int (*quotactl)(struct obd_device *, struct obd_export *, |
| 994 | struct obd_quotactl *); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 995 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 996 | /* pools methods */ |
Dan Carpenter | a13b1f3 | 2015-10-29 12:24:40 +0300 | [diff] [blame] | 997 | int (*pool_new)(struct obd_device *obd, char *poolname); |
| 998 | int (*pool_del)(struct obd_device *obd, char *poolname); |
| 999 | int (*pool_add)(struct obd_device *obd, char *poolname, |
| 1000 | char *ostname); |
| 1001 | int (*pool_rem)(struct obd_device *obd, char *poolname, |
| 1002 | char *ostname); |
| 1003 | void (*getref)(struct obd_device *obd); |
| 1004 | void (*putref)(struct obd_device *obd); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1005 | /* |
| 1006 | * NOTE: If adding ops, add another LPROCFS_OBD_OP_INIT() line |
| 1007 | * to lprocfs_alloc_obd_stats() in obdclass/lprocfs_status.c. |
Oleg Drokin | c56e256 | 2016-02-24 22:00:25 -0500 | [diff] [blame] | 1008 | * Also, add a wrapper function in include/linux/obd_class.h. |
| 1009 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1010 | }; |
| 1011 | |
| 1012 | enum { |
| 1013 | LUSTRE_OPC_MKDIR = (1 << 0), |
| 1014 | LUSTRE_OPC_SYMLINK = (1 << 1), |
| 1015 | LUSTRE_OPC_MKNOD = (1 << 2), |
| 1016 | LUSTRE_OPC_CREATE = (1 << 3), |
| 1017 | LUSTRE_OPC_ANY = (1 << 4) |
| 1018 | }; |
| 1019 | |
| 1020 | /* lmv structures */ |
| 1021 | #define MEA_MAGIC_LAST_CHAR 0xb2221ca1 |
| 1022 | #define MEA_MAGIC_ALL_CHARS 0xb222a11c |
| 1023 | #define MEA_MAGIC_HASH_SEGMENT 0xb222a11b |
| 1024 | |
| 1025 | #define MAX_HASH_SIZE_32 0x7fffffffUL |
| 1026 | #define MAX_HASH_SIZE 0x7fffffffffffffffULL |
| 1027 | #define MAX_HASH_HIGHEST_BIT 0x1000000000000000ULL |
| 1028 | |
| 1029 | struct lustre_md { |
| 1030 | struct mdt_body *body; |
| 1031 | struct lov_stripe_md *lsm; |
| 1032 | struct lmv_stripe_md *mea; |
| 1033 | #ifdef CONFIG_FS_POSIX_ACL |
| 1034 | struct posix_acl *posix_acl; |
| 1035 | #endif |
| 1036 | struct mdt_remote_perm *remote_perm; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1037 | }; |
| 1038 | |
| 1039 | struct md_open_data { |
| 1040 | struct obd_client_handle *mod_och; |
| 1041 | struct ptlrpc_request *mod_open_req; |
| 1042 | struct ptlrpc_request *mod_close_req; |
Hongchao Zhang | 63d4257 | 2014-02-28 21:16:37 -0500 | [diff] [blame] | 1043 | atomic_t mod_refcount; |
| 1044 | bool mod_is_create; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1045 | }; |
| 1046 | |
| 1047 | struct lookup_intent; |
| 1048 | |
| 1049 | struct md_ops { |
Dan Carpenter | df18a80 | 2015-10-29 12:26:36 +0300 | [diff] [blame] | 1050 | int (*getstatus)(struct obd_export *, struct lu_fid *); |
| 1051 | int (*null_inode)(struct obd_export *, const struct lu_fid *); |
| 1052 | int (*find_cbdata)(struct obd_export *, const struct lu_fid *, |
| 1053 | ldlm_iterator_t, void *); |
| 1054 | int (*close)(struct obd_export *, struct md_op_data *, |
| 1055 | struct md_open_data *, struct ptlrpc_request **); |
| 1056 | int (*create)(struct obd_export *, struct md_op_data *, |
| 1057 | const void *, int, int, __u32, __u32, cfs_cap_t, |
| 1058 | __u64, struct ptlrpc_request **); |
| 1059 | int (*done_writing)(struct obd_export *, struct md_op_data *, |
| 1060 | struct md_open_data *); |
| 1061 | int (*enqueue)(struct obd_export *, struct ldlm_enqueue_info *, |
| 1062 | struct lookup_intent *, struct md_op_data *, |
| 1063 | struct lustre_handle *, void *, int, |
| 1064 | struct ptlrpc_request **, __u64); |
| 1065 | int (*getattr)(struct obd_export *, struct md_op_data *, |
| 1066 | struct ptlrpc_request **); |
| 1067 | int (*getattr_name)(struct obd_export *, struct md_op_data *, |
| 1068 | struct ptlrpc_request **); |
| 1069 | int (*intent_lock)(struct obd_export *, struct md_op_data *, |
| 1070 | void *, int, struct lookup_intent *, int, |
| 1071 | struct ptlrpc_request **, |
| 1072 | ldlm_blocking_callback, __u64); |
| 1073 | int (*link)(struct obd_export *, struct md_op_data *, |
| 1074 | struct ptlrpc_request **); |
| 1075 | int (*rename)(struct obd_export *, struct md_op_data *, |
| 1076 | const char *, int, const char *, int, |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1077 | struct ptlrpc_request **); |
Dan Carpenter | df18a80 | 2015-10-29 12:26:36 +0300 | [diff] [blame] | 1078 | int (*is_subdir)(struct obd_export *, const struct lu_fid *, |
| 1079 | const struct lu_fid *, |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1080 | struct ptlrpc_request **); |
Dan Carpenter | df18a80 | 2015-10-29 12:26:36 +0300 | [diff] [blame] | 1081 | int (*setattr)(struct obd_export *, struct md_op_data *, void *, |
| 1082 | int, void *, int, struct ptlrpc_request **, |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1083 | struct md_open_data **mod); |
Dan Carpenter | df18a80 | 2015-10-29 12:26:36 +0300 | [diff] [blame] | 1084 | int (*sync)(struct obd_export *, const struct lu_fid *, |
| 1085 | struct ptlrpc_request **); |
| 1086 | int (*readpage)(struct obd_export *, struct md_op_data *, |
| 1087 | struct page **, struct ptlrpc_request **); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1088 | |
Dan Carpenter | df18a80 | 2015-10-29 12:26:36 +0300 | [diff] [blame] | 1089 | int (*unlink)(struct obd_export *, struct md_op_data *, |
| 1090 | struct ptlrpc_request **); |
| 1091 | |
| 1092 | int (*setxattr)(struct obd_export *, const struct lu_fid *, |
| 1093 | u64, const char *, const char *, int, int, int, __u32, |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1094 | struct ptlrpc_request **); |
| 1095 | |
Dan Carpenter | df18a80 | 2015-10-29 12:26:36 +0300 | [diff] [blame] | 1096 | int (*getxattr)(struct obd_export *, const struct lu_fid *, |
| 1097 | u64, const char *, const char *, int, int, int, |
| 1098 | struct ptlrpc_request **); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1099 | |
Dan Carpenter | df18a80 | 2015-10-29 12:26:36 +0300 | [diff] [blame] | 1100 | int (*init_ea_size)(struct obd_export *, int, int, int, int); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1101 | |
Dan Carpenter | df18a80 | 2015-10-29 12:26:36 +0300 | [diff] [blame] | 1102 | int (*get_lustre_md)(struct obd_export *, struct ptlrpc_request *, |
| 1103 | struct obd_export *, struct obd_export *, |
| 1104 | struct lustre_md *); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1105 | |
Dan Carpenter | df18a80 | 2015-10-29 12:26:36 +0300 | [diff] [blame] | 1106 | int (*free_lustre_md)(struct obd_export *, struct lustre_md *); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1107 | |
Dan Carpenter | df18a80 | 2015-10-29 12:26:36 +0300 | [diff] [blame] | 1108 | int (*set_open_replay_data)(struct obd_export *, |
| 1109 | struct obd_client_handle *, |
| 1110 | struct lookup_intent *); |
| 1111 | int (*clear_open_replay_data)(struct obd_export *, |
| 1112 | struct obd_client_handle *); |
| 1113 | int (*set_lock_data)(struct obd_export *, __u64 *, void *, __u64 *); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1114 | |
Oleg Drokin | 52ee0d2 | 2016-02-24 21:59:54 -0500 | [diff] [blame] | 1115 | enum ldlm_mode (*lock_match)(struct obd_export *, __u64, |
| 1116 | const struct lu_fid *, enum ldlm_type, |
| 1117 | ldlm_policy_data_t *, enum ldlm_mode, |
| 1118 | struct lustre_handle *); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1119 | |
Dan Carpenter | df18a80 | 2015-10-29 12:26:36 +0300 | [diff] [blame] | 1120 | int (*cancel_unused)(struct obd_export *, const struct lu_fid *, |
Oleg Drokin | 52ee0d2 | 2016-02-24 21:59:54 -0500 | [diff] [blame] | 1121 | ldlm_policy_data_t *, enum ldlm_mode, |
Oleg Drokin | f833ee4 | 2016-02-24 22:00:05 -0500 | [diff] [blame] | 1122 | enum ldlm_cancel_flags flags, void *opaque); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1123 | |
Dan Carpenter | df18a80 | 2015-10-29 12:26:36 +0300 | [diff] [blame] | 1124 | int (*intent_getattr_async)(struct obd_export *, |
| 1125 | struct md_enqueue_info *, |
| 1126 | struct ldlm_enqueue_info *); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1127 | |
Dan Carpenter | df18a80 | 2015-10-29 12:26:36 +0300 | [diff] [blame] | 1128 | int (*revalidate_lock)(struct obd_export *, struct lookup_intent *, |
| 1129 | struct lu_fid *, __u64 *bits); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1130 | |
| 1131 | /* |
| 1132 | * NOTE: If adding ops, add another LPROCFS_MD_OP_INIT() line to |
| 1133 | * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a |
| 1134 | * wrapper function in include/linux/obd_class.h. |
| 1135 | */ |
| 1136 | }; |
| 1137 | |
| 1138 | struct lsm_operations { |
| 1139 | void (*lsm_free)(struct lov_stripe_md *); |
| 1140 | int (*lsm_destroy)(struct lov_stripe_md *, struct obdo *oa, |
| 1141 | struct obd_export *md_exp); |
Oleg Drokin | 21aef7d | 2014-08-15 12:55:56 -0400 | [diff] [blame] | 1142 | void (*lsm_stripe_by_index)(struct lov_stripe_md *, int *, u64 *, |
| 1143 | u64 *); |
| 1144 | void (*lsm_stripe_by_offset)(struct lov_stripe_md *, int *, u64 *, |
| 1145 | u64 *); |
Hugues Morisset | b037976 | 2014-09-09 16:36:27 +0200 | [diff] [blame] | 1146 | int (*lsm_lmm_verify)(struct lov_mds_md *lmm, int lmm_bytes, |
Oleg Drokin | 10457d4 | 2016-02-26 01:49:50 -0500 | [diff] [blame] | 1147 | __u16 *stripe_count); |
Hugues Morisset | b037976 | 2014-09-09 16:36:27 +0200 | [diff] [blame] | 1148 | int (*lsm_unpackmd)(struct lov_obd *lov, struct lov_stripe_md *lsm, |
Oleg Drokin | 10457d4 | 2016-02-26 01:49:50 -0500 | [diff] [blame] | 1149 | struct lov_mds_md *lmm); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1150 | }; |
| 1151 | |
| 1152 | extern const struct lsm_operations lsm_v1_ops; |
| 1153 | extern const struct lsm_operations lsm_v3_ops; |
| 1154 | static inline const struct lsm_operations *lsm_op_find(int magic) |
| 1155 | { |
Greg Donald | a58a38a | 2014-08-21 12:40:35 -0500 | [diff] [blame] | 1156 | switch (magic) { |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1157 | case LOV_MAGIC_V1: |
| 1158 | return &lsm_v1_ops; |
| 1159 | case LOV_MAGIC_V3: |
| 1160 | return &lsm_v3_ops; |
| 1161 | default: |
| 1162 | CERROR("Cannot recognize lsm_magic %08x\n", magic); |
| 1163 | return NULL; |
| 1164 | } |
| 1165 | } |
| 1166 | |
| 1167 | /* Requests for obd_extent_calc() */ |
| 1168 | #define OBD_CALC_STRIPE_START 1 |
| 1169 | #define OBD_CALC_STRIPE_END 2 |
| 1170 | |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1171 | static inline struct md_open_data *obd_mod_alloc(void) |
| 1172 | { |
| 1173 | struct md_open_data *mod; |
Hugues Morisset | 498374f | 2014-09-09 16:36:25 +0200 | [diff] [blame] | 1174 | |
Oleg Drokin | af13af5 | 2015-09-16 12:26:56 -0400 | [diff] [blame] | 1175 | mod = kzalloc(sizeof(*mod), GFP_NOFS); |
Oleg Drokin | d2a1398 | 2016-02-16 00:46:52 -0500 | [diff] [blame] | 1176 | if (!mod) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1177 | return NULL; |
| 1178 | atomic_set(&mod->mod_refcount, 1); |
| 1179 | return mod; |
| 1180 | } |
| 1181 | |
| 1182 | #define obd_mod_get(mod) atomic_inc(&(mod)->mod_refcount) |
| 1183 | #define obd_mod_put(mod) \ |
| 1184 | ({ \ |
| 1185 | if (atomic_dec_and_test(&(mod)->mod_refcount)) { \ |
| 1186 | if ((mod)->mod_open_req) \ |
| 1187 | ptlrpc_req_finished((mod)->mod_open_req); \ |
Oleg Drokin | af13af5 | 2015-09-16 12:26:56 -0400 | [diff] [blame] | 1188 | kfree(mod); \ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1189 | } \ |
| 1190 | }) |
| 1191 | |
Oleg Drokin | 21aef7d | 2014-08-15 12:55:56 -0400 | [diff] [blame] | 1192 | void obdo_from_inode(struct obdo *dst, struct inode *src, u32 valid); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1193 | void obdo_set_parent_fid(struct obdo *dst, const struct lu_fid *parent); |
| 1194 | |
| 1195 | /* return 1 if client should be resend request */ |
| 1196 | static inline int client_should_resend(int resend, struct client_obd *cli) |
| 1197 | { |
| 1198 | return atomic_read(&cli->cl_resends) ? |
| 1199 | atomic_read(&cli->cl_resends) > resend : 1; |
| 1200 | } |
| 1201 | |
| 1202 | /** |
| 1203 | * Return device name for this device |
| 1204 | * |
| 1205 | * XXX: lu_device is declared before obd_device, while a pointer pointing |
| 1206 | * back to obd_device in lu_device, so this helper function defines here |
| 1207 | * instead of in lu_object.h |
| 1208 | */ |
| 1209 | static inline const char *lu_dev_name(const struct lu_device *lu_dev) |
| 1210 | { |
| 1211 | return lu_dev->ld_obd->obd_name; |
| 1212 | } |
| 1213 | |
| 1214 | static inline bool filename_is_volatile(const char *name, int namelen, int *idx) |
| 1215 | { |
| 1216 | const char *start; |
| 1217 | char *end; |
| 1218 | |
| 1219 | if (strncmp(name, LUSTRE_VOLATILE_HDR, LUSTRE_VOLATILE_HDR_LEN) != 0) |
| 1220 | return false; |
| 1221 | |
| 1222 | /* caller does not care of idx */ |
Oleg Drokin | d2a1398 | 2016-02-16 00:46:52 -0500 | [diff] [blame] | 1223 | if (!idx) |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1224 | return true; |
| 1225 | |
| 1226 | /* volatile file, the MDT can be set from name */ |
| 1227 | /* name format is LUSTRE_VOLATILE_HDR:[idx]: */ |
| 1228 | /* if no MDT is specified, use std way */ |
| 1229 | if (namelen < LUSTRE_VOLATILE_HDR_LEN + 2) |
| 1230 | goto bad_format; |
| 1231 | /* test for no MDT idx case */ |
| 1232 | if ((*(name + LUSTRE_VOLATILE_HDR_LEN) == ':') && |
| 1233 | (*(name + LUSTRE_VOLATILE_HDR_LEN + 1) == ':')) { |
| 1234 | *idx = -1; |
| 1235 | return true; |
| 1236 | } |
| 1237 | /* we have an idx, read it */ |
| 1238 | start = name + LUSTRE_VOLATILE_HDR_LEN + 1; |
Guenter Roeck | 4ad2adc9 | 2015-07-24 09:37:14 -0700 | [diff] [blame] | 1239 | *idx = simple_strtoul(start, &end, 0); |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1240 | /* error cases: |
| 1241 | * no digit, no trailing :, negative value |
| 1242 | */ |
| 1243 | if (((*idx == 0) && (end == start)) || |
| 1244 | (*end != ':') || (*idx < 0)) |
| 1245 | goto bad_format; |
| 1246 | |
| 1247 | return true; |
| 1248 | bad_format: |
| 1249 | /* bad format of mdt idx, we cannot return an error |
Oleg Drokin | c56e256 | 2016-02-24 22:00:25 -0500 | [diff] [blame] | 1250 | * to caller so we use hash algo |
| 1251 | */ |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1252 | CERROR("Bad volatile file name format: %s\n", |
| 1253 | name + LUSTRE_VOLATILE_HDR_LEN); |
| 1254 | return false; |
| 1255 | } |
| 1256 | |
| 1257 | static inline int cli_brw_size(struct obd_device *obd) |
| 1258 | { |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 1259 | return obd->u.cli.cl_max_pages_per_rpc << PAGE_SHIFT; |
Peng Tao | d7e09d0 | 2013-05-02 16:46:55 +0800 | [diff] [blame] | 1260 | } |
| 1261 | |
| 1262 | #endif /* __OBD_H */ |