blob: a6268718b76e6f067f66a7abd8adc4435cf94fbd [file] [log] [blame]
Peng Taod7e09d02013-05-02 16:46:55 +08001/*
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
18 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
19 *
20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
21 * CA 95054 USA or visit www.sun.com if you need additional information or
22 * have any questions.
23 *
24 * GPL HEADER END
25 */
26/*
27 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
28 * Use is subject to license terms.
29 *
30 * Copyright (c) 2011, 2012, Intel Corporation.
31 */
32/*
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
35 *
36 * lustre/llite/llite_capa.c
37 *
38 * Author: Lai Siyao <lsy@clusterfs.com>
39 */
40
41#define DEBUG_SUBSYSTEM S_LLITE
42
43#include <linux/fs.h>
Anil Belur576eb392014-06-25 14:57:28 +100044#include <linux/uaccess.h>
Peng Taod7e09d02013-05-02 16:46:55 +080045#include <linux/file.h>
46#include <linux/kmod.h>
47
Greg Kroah-Hartman67a235f2014-07-11 21:51:41 -070048#include "../include/lustre_lite.h"
Peng Taod7e09d02013-05-02 16:46:55 +080049#include "llite_internal.h"
50
51/* for obd_capa.c_list, client capa might stay in three places:
52 * 1. ll_capa_list.
53 * 2. ll_idle_capas.
54 * 3. stand alone: just allocated.
55 */
56
57/* capas for oss writeback and those failed to renew */
58static LIST_HEAD(ll_idle_capas);
59static struct ptlrpc_thread ll_capa_thread;
60static struct list_head *ll_capa_list = &capa_list[CAPA_SITE_CLIENT];
61
62/* llite capa renewal timer */
63struct timer_list ll_capa_timer;
64/* for debug: indicate whether capa on llite is enabled or not */
65static atomic_t ll_capa_debug = ATOMIC_INIT(0);
Anil Belur8bcf3c22014-06-25 14:57:27 +100066static unsigned long long ll_capa_renewed;
67static unsigned long long ll_capa_renewal_noent;
68static unsigned long long ll_capa_renewal_failed;
69static unsigned long long ll_capa_renewal_retries;
Peng Taod7e09d02013-05-02 16:46:55 +080070
John L. Hammond2d95f102014-04-27 13:07:05 -040071static int ll_update_capa(struct obd_capa *ocapa, struct lustre_capa *capa);
72
Greg Kroah-Hartmana649ad12014-07-12 00:27:46 -070073static inline void update_capa_timer(struct obd_capa *ocapa, unsigned long expiry)
Peng Taod7e09d02013-05-02 16:46:55 +080074{
Greg Kroah-Hartman699503b2014-07-12 01:03:41 -070075 if (time_before(expiry, ll_capa_timer.expires) ||
Peng Taod7e09d02013-05-02 16:46:55 +080076 !timer_pending(&ll_capa_timer)) {
77 mod_timer(&ll_capa_timer, expiry);
78 DEBUG_CAPA(D_SEC, &ocapa->c_capa,
79 "ll_capa_timer update: %lu/%lu by", expiry, jiffies);
80 }
81}
82
Greg Kroah-Hartmana649ad12014-07-12 00:27:46 -070083static inline unsigned long capa_renewal_time(struct obd_capa *ocapa)
Peng Taod7e09d02013-05-02 16:46:55 +080084{
85 return cfs_time_sub(ocapa->c_expiry,
86 cfs_time_seconds(ocapa->c_capa.lc_timeout) / 2);
87}
88
89static inline int capa_is_to_expire(struct obd_capa *ocapa)
90{
Greg Kroah-Hartman82173c62014-07-12 00:31:18 -070091 return time_before_eq(capa_renewal_time(ocapa), cfs_time_current());
Peng Taod7e09d02013-05-02 16:46:55 +080092}
93
94static inline int have_expired_capa(void)
95{
96 struct obd_capa *ocapa = NULL;
97 int expired = 0;
98
99 /* if ll_capa_list has client capa to expire or ll_idle_capas has
100 * expired capa, return 1.
101 */
102 spin_lock(&capa_lock);
103 if (!list_empty(ll_capa_list)) {
104 ocapa = list_entry(ll_capa_list->next, struct obd_capa,
105 c_list);
106 expired = capa_is_to_expire(ocapa);
107 if (!expired)
108 update_capa_timer(ocapa, capa_renewal_time(ocapa));
109 } else if (!list_empty(&ll_idle_capas)) {
110 ocapa = list_entry(ll_idle_capas.next, struct obd_capa,
111 c_list);
112 expired = capa_is_expired(ocapa);
113 if (!expired)
114 update_capa_timer(ocapa, ocapa->c_expiry);
115 }
116 spin_unlock(&capa_lock);
117
118 if (expired)
119 DEBUG_CAPA(D_SEC, &ocapa->c_capa, "expired");
120 return expired;
121}
122
123static void sort_add_capa(struct obd_capa *ocapa, struct list_head *head)
124{
125 struct obd_capa *tmp;
126 struct list_head *before = NULL;
127
128 /* TODO: client capa is sorted by expiry, this could be optimized */
129 list_for_each_entry_reverse(tmp, head, c_list) {
130 if (cfs_time_aftereq(ocapa->c_expiry, tmp->c_expiry)) {
131 before = &tmp->c_list;
132 break;
133 }
134 }
135
136 LASSERT(&ocapa->c_list != before);
137 list_add(&ocapa->c_list, before ?: head);
138}
139
140static inline int obd_capa_open_count(struct obd_capa *oc)
141{
142 struct ll_inode_info *lli = ll_i2info(oc->u.cli.inode);
Aparna Karuthodi06d0c492015-06-03 15:03:57 +0530143
Peng Taod7e09d02013-05-02 16:46:55 +0800144 return atomic_read(&lli->lli_open_count);
145}
146
147static void ll_delete_capa(struct obd_capa *ocapa)
148{
149 struct ll_inode_info *lli = ll_i2info(ocapa->u.cli.inode);
150
151 if (capa_for_mds(&ocapa->c_capa)) {
152 LASSERT(lli->lli_mds_capa == ocapa);
153 lli->lli_mds_capa = NULL;
154 } else if (capa_for_oss(&ocapa->c_capa)) {
155 list_del_init(&ocapa->u.cli.lli_list);
156 }
157
158 DEBUG_CAPA(D_SEC, &ocapa->c_capa, "free client");
159 list_del_init(&ocapa->c_list);
160 capa_count[CAPA_SITE_CLIENT]--;
161 /* release the ref when alloc */
162 capa_put(ocapa);
163}
164
165/* three places where client capa is deleted:
166 * 1. capa_thread_main(), main place to delete expired capa.
167 * 2. ll_clear_inode_capas() in ll_clear_inode().
168 * 3. ll_truncate_free_capa() delete truncate capa explicitly in ll_setattr_ost().
169 */
170static int capa_thread_main(void *unused)
171{
172 struct obd_capa *ocapa, *tmp, *next;
173 struct inode *inode = NULL;
174 struct l_wait_info lwi = { 0 };
175 int rc;
Peng Taod7e09d02013-05-02 16:46:55 +0800176
177 thread_set_flags(&ll_capa_thread, SVC_RUNNING);
178 wake_up(&ll_capa_thread.t_ctl_waitq);
179
180 while (1) {
181 l_wait_event(ll_capa_thread.t_ctl_waitq,
182 !thread_is_running(&ll_capa_thread) ||
183 have_expired_capa(),
184 &lwi);
185
186 if (!thread_is_running(&ll_capa_thread))
187 break;
188
189 next = NULL;
190
191 spin_lock(&capa_lock);
192 list_for_each_entry_safe(ocapa, tmp, ll_capa_list, c_list) {
193 __u64 ibits;
194
195 LASSERT(ocapa->c_capa.lc_opc != CAPA_OPC_OSS_TRUNC);
196
197 if (!capa_is_to_expire(ocapa)) {
198 next = ocapa;
199 break;
200 }
201
202 list_del_init(&ocapa->c_list);
203
204 /* for MDS capability, only renew those which belong to
205 * dir, or its inode is opened, or client holds LOOKUP
206 * lock.
207 */
208 /* ibits may be changed by ll_have_md_lock() so we have
209 * to set it each time */
210 ibits = MDS_INODELOCK_LOOKUP;
211 if (capa_for_mds(&ocapa->c_capa) &&
212 !S_ISDIR(ocapa->u.cli.inode->i_mode) &&
213 obd_capa_open_count(ocapa) == 0 &&
214 !ll_have_md_lock(ocapa->u.cli.inode,
215 &ibits, LCK_MINMODE)) {
216 DEBUG_CAPA(D_SEC, &ocapa->c_capa,
217 "skip renewal for");
218 sort_add_capa(ocapa, &ll_idle_capas);
219 continue;
220 }
221
222 /* for OSS capability, only renew those whose inode is
223 * opened.
224 */
225 if (capa_for_oss(&ocapa->c_capa) &&
226 obd_capa_open_count(ocapa) == 0) {
227 /* oss capa with open count == 0 won't renew,
228 * move to idle list */
229 sort_add_capa(ocapa, &ll_idle_capas);
230 continue;
231 }
232
233 /* NB iput() is in ll_update_capa() */
234 inode = igrab(ocapa->u.cli.inode);
235 if (inode == NULL) {
236 DEBUG_CAPA(D_ERROR, &ocapa->c_capa,
237 "igrab failed for");
238 continue;
239 }
240
241 capa_get(ocapa);
242 ll_capa_renewed++;
243 spin_unlock(&capa_lock);
244 rc = md_renew_capa(ll_i2mdexp(inode), ocapa,
245 ll_update_capa);
246 spin_lock(&capa_lock);
247 if (rc) {
248 DEBUG_CAPA(D_ERROR, &ocapa->c_capa,
249 "renew failed: %d", rc);
250 ll_capa_renewal_failed++;
251 }
252 }
253
254 if (next)
255 update_capa_timer(next, capa_renewal_time(next));
256
257 list_for_each_entry_safe(ocapa, tmp, &ll_idle_capas,
258 c_list) {
259 if (!capa_is_expired(ocapa)) {
260 if (!next)
261 update_capa_timer(ocapa,
262 ocapa->c_expiry);
263 break;
264 }
265
266 if (atomic_read(&ocapa->c_refc) > 1) {
267 DEBUG_CAPA(D_SEC, &ocapa->c_capa,
268 "expired(c_refc %d), don't release",
269 atomic_read(&ocapa->c_refc));
270 /* don't try to renew any more */
271 list_del_init(&ocapa->c_list);
272 continue;
273 }
274
275 /* expired capa is released. */
276 DEBUG_CAPA(D_SEC, &ocapa->c_capa, "release expired");
277 ll_delete_capa(ocapa);
278 }
279
280 spin_unlock(&capa_lock);
281 }
282
283 thread_set_flags(&ll_capa_thread, SVC_STOPPED);
284 wake_up(&ll_capa_thread.t_ctl_waitq);
Greg Kroah-Hartman0a3bdb02013-08-03 10:35:28 +0800285 return 0;
Peng Taod7e09d02013-05-02 16:46:55 +0800286}
287
288void ll_capa_timer_callback(unsigned long unused)
289{
290 wake_up(&ll_capa_thread.t_ctl_waitq);
291}
292
293int ll_capa_thread_start(void)
294{
Greg Kroah-Hartman68b636b2013-08-04 08:56:42 +0800295 struct task_struct *task;
Peng Taod7e09d02013-05-02 16:46:55 +0800296
297 init_waitqueue_head(&ll_capa_thread.t_ctl_waitq);
298
299 task = kthread_run(capa_thread_main, NULL, "ll_capa");
300 if (IS_ERR(task)) {
301 CERROR("cannot start expired capa thread: rc %ld\n",
302 PTR_ERR(task));
Greg Kroah-Hartman0a3bdb02013-08-03 10:35:28 +0800303 return PTR_ERR(task);
Peng Taod7e09d02013-05-02 16:46:55 +0800304 }
305 wait_event(ll_capa_thread.t_ctl_waitq,
306 thread_is_running(&ll_capa_thread));
307
Greg Kroah-Hartman0a3bdb02013-08-03 10:35:28 +0800308 return 0;
Peng Taod7e09d02013-05-02 16:46:55 +0800309}
310
311void ll_capa_thread_stop(void)
312{
313 thread_set_flags(&ll_capa_thread, SVC_STOPPING);
314 wake_up(&ll_capa_thread.t_ctl_waitq);
315 wait_event(ll_capa_thread.t_ctl_waitq,
316 thread_is_stopped(&ll_capa_thread));
317}
318
319struct obd_capa *ll_osscapa_get(struct inode *inode, __u64 opc)
320{
321 struct ll_inode_info *lli = ll_i2info(inode);
322 struct obd_capa *ocapa;
323 int found = 0;
324
Peng Taod7e09d02013-05-02 16:46:55 +0800325 if ((ll_i2sbi(inode)->ll_flags & LL_SBI_OSS_CAPA) == 0)
Greg Kroah-Hartman0a3bdb02013-08-03 10:35:28 +0800326 return NULL;
Peng Taod7e09d02013-05-02 16:46:55 +0800327
328 LASSERT(opc == CAPA_OPC_OSS_WRITE || opc == CAPA_OPC_OSS_RW ||
329 opc == CAPA_OPC_OSS_TRUNC);
330
331 spin_lock(&capa_lock);
332 list_for_each_entry(ocapa, &lli->lli_oss_capas, u.cli.lli_list) {
333 if (capa_is_expired(ocapa))
334 continue;
335 if ((opc & CAPA_OPC_OSS_WRITE) &&
336 capa_opc_supported(&ocapa->c_capa, CAPA_OPC_OSS_WRITE)) {
337 found = 1;
338 break;
339 } else if ((opc & CAPA_OPC_OSS_READ) &&
340 capa_opc_supported(&ocapa->c_capa,
341 CAPA_OPC_OSS_READ)) {
342 found = 1;
343 break;
344 } else if ((opc & CAPA_OPC_OSS_TRUNC) &&
345 capa_opc_supported(&ocapa->c_capa, opc)) {
346 found = 1;
347 break;
348 }
349 }
350
351 if (found) {
352 LASSERT(lu_fid_eq(capa_fid(&ocapa->c_capa),
353 ll_inode2fid(inode)));
354 LASSERT(ocapa->c_site == CAPA_SITE_CLIENT);
355
356 capa_get(ocapa);
357
358 DEBUG_CAPA(D_SEC, &ocapa->c_capa, "found client");
359 } else {
360 ocapa = NULL;
361
362 if (atomic_read(&ll_capa_debug)) {
Greg Kroah-Hartman55f5a822014-07-12 20:26:07 -0700363 CERROR("no capability for "DFID" opc %#llx\n",
Peng Taod7e09d02013-05-02 16:46:55 +0800364 PFID(&lli->lli_fid), opc);
365 atomic_set(&ll_capa_debug, 0);
366 }
367 }
368 spin_unlock(&capa_lock);
369
Greg Kroah-Hartman0a3bdb02013-08-03 10:35:28 +0800370 return ocapa;
Peng Taod7e09d02013-05-02 16:46:55 +0800371}
372EXPORT_SYMBOL(ll_osscapa_get);
373
374struct obd_capa *ll_mdscapa_get(struct inode *inode)
375{
376 struct ll_inode_info *lli = ll_i2info(inode);
377 struct obd_capa *ocapa;
Peng Taod7e09d02013-05-02 16:46:55 +0800378
379 LASSERT(inode != NULL);
380
381 if ((ll_i2sbi(inode)->ll_flags & LL_SBI_MDS_CAPA) == 0)
Greg Kroah-Hartman0a3bdb02013-08-03 10:35:28 +0800382 return NULL;
Peng Taod7e09d02013-05-02 16:46:55 +0800383
384 spin_lock(&capa_lock);
385 ocapa = capa_get(lli->lli_mds_capa);
386 spin_unlock(&capa_lock);
387 if (!ocapa && atomic_read(&ll_capa_debug)) {
388 CERROR("no mds capability for "DFID"\n", PFID(&lli->lli_fid));
389 atomic_set(&ll_capa_debug, 0);
390 }
391
Greg Kroah-Hartman0a3bdb02013-08-03 10:35:28 +0800392 return ocapa;
Peng Taod7e09d02013-05-02 16:46:55 +0800393}
394
395static struct obd_capa *do_add_mds_capa(struct inode *inode,
396 struct obd_capa *ocapa)
397{
398 struct ll_inode_info *lli = ll_i2info(inode);
399 struct obd_capa *old = lli->lli_mds_capa;
400 struct lustre_capa *capa = &ocapa->c_capa;
401
402 if (!old) {
403 ocapa->u.cli.inode = inode;
404 lli->lli_mds_capa = ocapa;
405 capa_count[CAPA_SITE_CLIENT]++;
406
407 DEBUG_CAPA(D_SEC, capa, "add MDS");
408 } else {
409 spin_lock(&old->c_lock);
410 old->c_capa = *capa;
411 spin_unlock(&old->c_lock);
412
413 DEBUG_CAPA(D_SEC, capa, "update MDS");
414
415 capa_put(ocapa);
416 ocapa = old;
417 }
418 return ocapa;
419}
420
421static struct obd_capa *do_lookup_oss_capa(struct inode *inode, int opc)
422{
423 struct ll_inode_info *lli = ll_i2info(inode);
424 struct obd_capa *ocapa;
425
426 /* inside capa_lock */
427 list_for_each_entry(ocapa, &lli->lli_oss_capas, u.cli.lli_list) {
428 if ((capa_opc(&ocapa->c_capa) & opc) != opc)
429 continue;
430
431 LASSERT(lu_fid_eq(capa_fid(&ocapa->c_capa),
432 ll_inode2fid(inode)));
433 LASSERT(ocapa->c_site == CAPA_SITE_CLIENT);
434
435 DEBUG_CAPA(D_SEC, &ocapa->c_capa, "found client");
436 return ocapa;
437 }
438
439 return NULL;
440}
441
442static inline void inode_add_oss_capa(struct inode *inode,
443 struct obd_capa *ocapa)
444{
445 struct ll_inode_info *lli = ll_i2info(inode);
446 struct obd_capa *tmp;
447 struct list_head *next = NULL;
448
449 /* capa is sorted in lli_oss_capas so lookup can always find the
450 * latest one */
451 list_for_each_entry(tmp, &lli->lli_oss_capas, u.cli.lli_list) {
452 if (cfs_time_after(ocapa->c_expiry, tmp->c_expiry)) {
453 next = &tmp->u.cli.lli_list;
454 break;
455 }
456 }
457 LASSERT(&ocapa->u.cli.lli_list != next);
458 list_move_tail(&ocapa->u.cli.lli_list, next ?: &lli->lli_oss_capas);
459}
460
461static struct obd_capa *do_add_oss_capa(struct inode *inode,
462 struct obd_capa *ocapa)
463{
464 struct obd_capa *old;
465 struct lustre_capa *capa = &ocapa->c_capa;
466
467 LASSERTF(S_ISREG(inode->i_mode),
468 "inode has oss capa, but not regular file, mode: %d\n",
469 inode->i_mode);
470
471 /* FIXME: can't replace it so easily with fine-grained opc */
472 old = do_lookup_oss_capa(inode, capa_opc(capa) & CAPA_OPC_OSS_ONLY);
473 if (!old) {
474 ocapa->u.cli.inode = inode;
475 INIT_LIST_HEAD(&ocapa->u.cli.lli_list);
476 capa_count[CAPA_SITE_CLIENT]++;
477
478 DEBUG_CAPA(D_SEC, capa, "add OSS");
479 } else {
480 spin_lock(&old->c_lock);
481 old->c_capa = *capa;
482 spin_unlock(&old->c_lock);
483
484 DEBUG_CAPA(D_SEC, capa, "update OSS");
485
486 capa_put(ocapa);
487 ocapa = old;
488 }
489
490 inode_add_oss_capa(inode, ocapa);
491 return ocapa;
492}
493
494struct obd_capa *ll_add_capa(struct inode *inode, struct obd_capa *ocapa)
495{
496 spin_lock(&capa_lock);
497 ocapa = capa_for_mds(&ocapa->c_capa) ? do_add_mds_capa(inode, ocapa) :
498 do_add_oss_capa(inode, ocapa);
499
500 /* truncate capa won't renew */
501 if (ocapa->c_capa.lc_opc != CAPA_OPC_OSS_TRUNC) {
502 set_capa_expiry(ocapa);
503 list_del_init(&ocapa->c_list);
504 sort_add_capa(ocapa, ll_capa_list);
505
506 update_capa_timer(ocapa, capa_renewal_time(ocapa));
507 }
508
509 spin_unlock(&capa_lock);
510
511 atomic_set(&ll_capa_debug, 1);
512 return ocapa;
513}
514
Greg Kroah-Hartmana649ad12014-07-12 00:27:46 -0700515static inline void delay_capa_renew(struct obd_capa *oc, unsigned long delay)
Peng Taod7e09d02013-05-02 16:46:55 +0800516{
517 /* NB: set a fake expiry for this capa to prevent it renew too soon */
518 oc->c_expiry = cfs_time_add(oc->c_expiry, cfs_time_seconds(delay));
519}
520
John L. Hammond2d95f102014-04-27 13:07:05 -0400521static int ll_update_capa(struct obd_capa *ocapa, struct lustre_capa *capa)
Peng Taod7e09d02013-05-02 16:46:55 +0800522{
523 struct inode *inode = ocapa->u.cli.inode;
524 int rc = 0;
Peng Taod7e09d02013-05-02 16:46:55 +0800525
526 LASSERT(ocapa);
527
528 if (IS_ERR(capa)) {
529 /* set error code */
530 rc = PTR_ERR(capa);
531 spin_lock(&capa_lock);
532 if (rc == -ENOENT) {
533 DEBUG_CAPA(D_SEC, &ocapa->c_capa,
534 "renewal canceled because object removed");
535 ll_capa_renewal_noent++;
536 } else {
537 ll_capa_renewal_failed++;
538
539 /* failed capa won't be renewed any longer, but if -EIO,
540 * client might be doing recovery, retry in 2 min. */
541 if (rc == -EIO && !capa_is_expired(ocapa)) {
542 delay_capa_renew(ocapa, 120);
543 DEBUG_CAPA(D_ERROR, &ocapa->c_capa,
Joe Perches2d00bd12014-11-23 11:28:50 -0800544 "renewal failed: -EIO, retry in 2 mins");
Peng Taod7e09d02013-05-02 16:46:55 +0800545 ll_capa_renewal_retries++;
Julia Lawall34e1f2b2014-08-30 16:24:55 +0200546 goto retry;
Peng Taod7e09d02013-05-02 16:46:55 +0800547 } else {
548 DEBUG_CAPA(D_ERROR, &ocapa->c_capa,
549 "renewal failed(rc: %d) for", rc);
550 }
551 }
552
553 list_del_init(&ocapa->c_list);
554 sort_add_capa(ocapa, &ll_idle_capas);
555 spin_unlock(&capa_lock);
556
557 capa_put(ocapa);
558 iput(inode);
Greg Kroah-Hartman0a3bdb02013-08-03 10:35:28 +0800559 return rc;
Peng Taod7e09d02013-05-02 16:46:55 +0800560 }
561
562 spin_lock(&ocapa->c_lock);
563 LASSERT(!memcmp(&ocapa->c_capa, capa,
564 offsetof(struct lustre_capa, lc_opc)));
565 ocapa->c_capa = *capa;
566 set_capa_expiry(ocapa);
567 spin_unlock(&ocapa->c_lock);
568
569 spin_lock(&capa_lock);
570 if (capa_for_oss(capa))
571 inode_add_oss_capa(inode, ocapa);
572 DEBUG_CAPA(D_SEC, capa, "renew");
Peng Taod7e09d02013-05-02 16:46:55 +0800573retry:
574 list_del_init(&ocapa->c_list);
575 sort_add_capa(ocapa, ll_capa_list);
576 update_capa_timer(ocapa, capa_renewal_time(ocapa));
577 spin_unlock(&capa_lock);
578
579 capa_put(ocapa);
580 iput(inode);
581 return rc;
582}
583
584void ll_capa_open(struct inode *inode)
585{
586 struct ll_inode_info *lli = ll_i2info(inode);
587
588 if ((ll_i2sbi(inode)->ll_flags & (LL_SBI_MDS_CAPA | LL_SBI_OSS_CAPA))
589 == 0)
590 return;
591
592 if (!S_ISREG(inode->i_mode))
593 return;
594
595 atomic_inc(&lli->lli_open_count);
596}
597
598void ll_capa_close(struct inode *inode)
599{
600 struct ll_inode_info *lli = ll_i2info(inode);
601
602 if ((ll_i2sbi(inode)->ll_flags & (LL_SBI_MDS_CAPA | LL_SBI_OSS_CAPA))
603 == 0)
604 return;
605
606 if (!S_ISREG(inode->i_mode))
607 return;
608
609 atomic_dec(&lli->lli_open_count);
610}
611
612/* delete CAPA_OPC_OSS_TRUNC only */
613void ll_truncate_free_capa(struct obd_capa *ocapa)
614{
615 if (!ocapa)
616 return;
617
618 LASSERT(ocapa->c_capa.lc_opc & CAPA_OPC_OSS_TRUNC);
619 DEBUG_CAPA(D_SEC, &ocapa->c_capa, "free truncate");
620
621 /* release ref when find */
622 capa_put(ocapa);
623 if (likely(ocapa->c_capa.lc_opc == CAPA_OPC_OSS_TRUNC)) {
624 spin_lock(&capa_lock);
625 ll_delete_capa(ocapa);
626 spin_unlock(&capa_lock);
627 }
628}
629
630void ll_clear_inode_capas(struct inode *inode)
631{
632 struct ll_inode_info *lli = ll_i2info(inode);
633 struct obd_capa *ocapa, *tmp;
634
635 spin_lock(&capa_lock);
636 ocapa = lli->lli_mds_capa;
637 if (ocapa)
638 ll_delete_capa(ocapa);
639
640 list_for_each_entry_safe(ocapa, tmp, &lli->lli_oss_capas,
641 u.cli.lli_list)
642 ll_delete_capa(ocapa);
643 spin_unlock(&capa_lock);
644}
645
646void ll_print_capa_stat(struct ll_sb_info *sbi)
647{
648 if (sbi->ll_flags & (LL_SBI_MDS_CAPA | LL_SBI_OSS_CAPA))
649 LCONSOLE_INFO("Fid capabilities renewed: %llu\n"
650 "Fid capabilities renewal ENOENT: %llu\n"
651 "Fid capabilities failed to renew: %llu\n"
652 "Fid capabilities renewal retries: %llu\n",
653 ll_capa_renewed, ll_capa_renewal_noent,
654 ll_capa_renewal_failed, ll_capa_renewal_retries);
655}