Whamcloud - gitweb
LU-871 build: change %L printk format to %ll
[fs/lustre-release.git] / lustre / llite / llite_capa.c
1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=8:tabstop=8:
3  *
4  * GPL HEADER START
5  *
6  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 only,
10  * as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * General Public License version 2 for more details (a copy is included
16  * in the LICENSE file that accompanied this code).
17  *
18  * You should have received a copy of the GNU General Public License
19  * version 2 along with this program; If not, see
20  * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
21  *
22  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23  * CA 95054 USA or visit www.sun.com if you need additional information or
24  * have any questions.
25  *
26  * GPL HEADER END
27  */
28 /*
29  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
30  * Use is subject to license terms.
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>
44 #include <linux/version.h>
45 #include <asm/uaccess.h>
46 #include <linux/file.h>
47 #include <linux/kmod.h>
48
49 #include <lustre_lite.h>
50 #include "llite_internal.h"
51
52 /* for obd_capa.c_list, client capa might stay in three places:
53  * 1. ll_capa_list.
54  * 2. ll_idle_capas.
55  * 3. stand alone: just allocated.
56  */
57
58 /* capas for oss writeback and those failed to renew */
59 static CFS_LIST_HEAD(ll_idle_capas);
60 static struct ptlrpc_thread ll_capa_thread;
61 static cfs_list_t *ll_capa_list = &capa_list[CAPA_SITE_CLIENT];
62
63 /* llite capa renewal timer */
64 struct timer_list ll_capa_timer;
65 /* for debug: indicate whether capa on llite is enabled or not */
66 static cfs_atomic_t ll_capa_debug = CFS_ATOMIC_INIT(0);
67 static unsigned long long ll_capa_renewed = 0;
68 static unsigned long long ll_capa_renewal_noent = 0;
69 static unsigned long long ll_capa_renewal_failed = 0;
70 static unsigned long long ll_capa_renewal_retries = 0;
71
72 static inline void update_capa_timer(struct obd_capa *ocapa, cfs_time_t expiry)
73 {
74         if (cfs_time_before(expiry, ll_capa_timer.expires) ||
75             !timer_pending(&ll_capa_timer)) {
76                 mod_timer(&ll_capa_timer, expiry);
77                 DEBUG_CAPA(D_SEC, &ocapa->c_capa,
78                            "ll_capa_timer update: %lu/%lu by", expiry, jiffies);
79         }
80 }
81
82 static inline cfs_time_t capa_renewal_time(struct obd_capa *ocapa)
83 {
84         return cfs_time_sub(ocapa->c_expiry,
85                             cfs_time_seconds(ocapa->c_capa.lc_timeout) / 2);
86 }
87
88 static inline int capa_is_to_expire(struct obd_capa *ocapa)
89 {
90         return cfs_time_beforeq(capa_renewal_time(ocapa), cfs_time_current());
91 }
92
93 static inline int have_expired_capa(void)
94 {
95         struct obd_capa *ocapa = NULL;
96         int expired = 0;
97
98         /* if ll_capa_list has client capa to expire or ll_idle_capas has
99          * expired capa, return 1.
100          */
101         cfs_spin_lock(&capa_lock);
102         if (!cfs_list_empty(ll_capa_list)) {
103                 ocapa = cfs_list_entry(ll_capa_list->next, struct obd_capa,
104                                        c_list);
105                 expired = capa_is_to_expire(ocapa);
106                 if (!expired)
107                         update_capa_timer(ocapa, capa_renewal_time(ocapa));
108         } else if (!cfs_list_empty(&ll_idle_capas)) {
109                 ocapa = cfs_list_entry(ll_idle_capas.next, struct obd_capa,
110                                        c_list);
111                 expired = capa_is_expired(ocapa);
112                 if (!expired)
113                         update_capa_timer(ocapa, ocapa->c_expiry);
114         }
115         cfs_spin_unlock(&capa_lock);
116
117         if (expired)
118                 DEBUG_CAPA(D_SEC, &ocapa->c_capa, "expired");
119         return expired;
120 }
121
122 static inline int ll_capa_check_stop(void)
123 {
124         return (ll_capa_thread.t_flags & SVC_STOPPING) ? 1: 0;
125 }
126
127 static void sort_add_capa(struct obd_capa *ocapa, cfs_list_t *head)
128 {
129         struct obd_capa *tmp;
130         cfs_list_t *before = NULL;
131
132         /* TODO: client capa is sorted by expiry, this could be optimized */
133         cfs_list_for_each_entry_reverse(tmp, head, c_list) {
134                 if (cfs_time_aftereq(ocapa->c_expiry, tmp->c_expiry)) {
135                         before = &tmp->c_list;
136                         break;
137                 }
138         }
139
140         LASSERT(&ocapa->c_list != before);
141         cfs_list_add(&ocapa->c_list, before ?: head);
142 }
143
144 static inline int obd_capa_open_count(struct obd_capa *oc)
145 {
146         struct ll_inode_info *lli = ll_i2info(oc->u.cli.inode);
147         return cfs_atomic_read(&lli->lli_open_count);
148 }
149
150 static void ll_delete_capa(struct obd_capa *ocapa)
151 {
152         struct ll_inode_info *lli = ll_i2info(ocapa->u.cli.inode);
153
154         if (capa_for_mds(&ocapa->c_capa)) {
155                 LASSERT(lli->lli_mds_capa == ocapa);
156                 lli->lli_mds_capa = NULL;
157         } else if (capa_for_oss(&ocapa->c_capa)) {
158                 cfs_list_del_init(&ocapa->u.cli.lli_list);
159         }
160
161         DEBUG_CAPA(D_SEC, &ocapa->c_capa, "free client");
162         cfs_list_del_init(&ocapa->c_list);
163         capa_count[CAPA_SITE_CLIENT]--;
164         /* release the ref when alloc */
165         capa_put(ocapa);
166 }
167
168 /* three places where client capa is deleted:
169  * 1. capa_thread_main(), main place to delete expired capa.
170  * 2. ll_clear_inode_capas() in ll_clear_inode().
171  * 3. ll_truncate_free_capa() delete truncate capa explicitly in ll_truncate().
172  */
173 static int capa_thread_main(void *unused)
174 {
175         struct obd_capa *ocapa, *tmp, *next;
176         struct inode *inode = NULL;
177         struct l_wait_info lwi = { 0 };
178         int rc;
179         ENTRY;
180
181         cfs_daemonize("ll_capa");
182
183         ll_capa_thread.t_flags = SVC_RUNNING;
184         cfs_waitq_signal(&ll_capa_thread.t_ctl_waitq);
185
186         while (1) {
187                 l_wait_event(ll_capa_thread.t_ctl_waitq,
188                              (ll_capa_check_stop() || have_expired_capa()),
189                              &lwi);
190
191                 if (ll_capa_check_stop())
192                         break;
193
194                 next = NULL;
195
196                 cfs_spin_lock(&capa_lock);
197                 cfs_list_for_each_entry_safe(ocapa, tmp, ll_capa_list, c_list) {
198                         __u64 ibits;
199
200                         LASSERT(ocapa->c_capa.lc_opc != CAPA_OPC_OSS_TRUNC);
201
202                         if (!capa_is_to_expire(ocapa)) {
203                                 next = ocapa;
204                                 break;
205                         }
206
207                         cfs_list_del_init(&ocapa->c_list);
208
209                         /* for MDS capability, only renew those which belong to
210                          * dir, or its inode is opened, or client holds LOOKUP
211                          * lock.
212                          */
213                         /* ibits may be changed by ll_have_md_lock() so we have
214                          * to set it each time */
215                         ibits = MDS_INODELOCK_LOOKUP;
216                         if (capa_for_mds(&ocapa->c_capa) &&
217                             !S_ISDIR(ocapa->u.cli.inode->i_mode) &&
218                             obd_capa_open_count(ocapa) == 0 &&
219                             !ll_have_md_lock(ocapa->u.cli.inode,
220                                              &ibits, LCK_MINMODE)) {
221                                 DEBUG_CAPA(D_SEC, &ocapa->c_capa,
222                                            "skip renewal for");
223                                 sort_add_capa(ocapa, &ll_idle_capas);
224                                 continue;
225                         }
226
227                         /* for OSS capability, only renew those whose inode is
228                          * opened.
229                          */
230                         if (capa_for_oss(&ocapa->c_capa) &&
231                             obd_capa_open_count(ocapa) == 0) {
232                                 /* oss capa with open count == 0 won't renew,
233                                  * move to idle list */
234                                 sort_add_capa(ocapa, &ll_idle_capas);
235                                 continue;
236                         }
237
238                         /* NB iput() is in ll_update_capa() */
239                         inode = igrab(ocapa->u.cli.inode);
240                         if (inode == NULL) {
241                                 DEBUG_CAPA(D_ERROR, &ocapa->c_capa,
242                                            "igrab failed for");
243                                 continue;
244                         }
245
246                         capa_get(ocapa);
247                         ll_capa_renewed++;
248                         cfs_spin_unlock(&capa_lock);
249                         rc = md_renew_capa(ll_i2mdexp(inode), ocapa,
250                                            ll_update_capa);
251                         cfs_spin_lock(&capa_lock);
252                         if (rc) {
253                                 DEBUG_CAPA(D_ERROR, &ocapa->c_capa,
254                                            "renew failed: %d", rc);
255                                 ll_capa_renewal_failed++;
256                         }
257                 }
258
259                 if (next)
260                         update_capa_timer(next, capa_renewal_time(next));
261
262                 cfs_list_for_each_entry_safe(ocapa, tmp, &ll_idle_capas,
263                                              c_list) {
264                         if (!capa_is_expired(ocapa)) {
265                                 if (!next)
266                                         update_capa_timer(ocapa,
267                                                           ocapa->c_expiry);
268                                 break;
269                         }
270
271                         if (cfs_atomic_read(&ocapa->c_refc) > 1) {
272                                 DEBUG_CAPA(D_SEC, &ocapa->c_capa,
273                                            "expired(c_refc %d), don't release",
274                                            cfs_atomic_read(&ocapa->c_refc));
275                                 /* don't try to renew any more */
276                                 cfs_list_del_init(&ocapa->c_list);
277                                 continue;
278                         }
279
280                         /* expired capa is released. */
281                         DEBUG_CAPA(D_SEC, &ocapa->c_capa, "release expired");
282                         ll_delete_capa(ocapa);
283                 }
284
285                 cfs_spin_unlock(&capa_lock);
286         }
287
288         ll_capa_thread.t_flags = SVC_STOPPED;
289         cfs_waitq_signal(&ll_capa_thread.t_ctl_waitq);
290         RETURN(0);
291 }
292
293 void ll_capa_timer_callback(unsigned long unused)
294 {
295         cfs_waitq_signal(&ll_capa_thread.t_ctl_waitq);
296 }
297
298 int ll_capa_thread_start(void)
299 {
300         int rc;
301         ENTRY;
302
303         cfs_waitq_init(&ll_capa_thread.t_ctl_waitq);
304
305         rc = cfs_create_thread(capa_thread_main, NULL, 0);
306         if (rc < 0) {
307                 CERROR("cannot start expired capa thread: rc %d\n", rc);
308                 RETURN(rc);
309         }
310         cfs_wait_event(ll_capa_thread.t_ctl_waitq,
311                        ll_capa_thread.t_flags & SVC_RUNNING);
312
313         RETURN(0);
314 }
315
316 void ll_capa_thread_stop(void)
317 {
318         ll_capa_thread.t_flags = SVC_STOPPING;
319         cfs_waitq_signal(&ll_capa_thread.t_ctl_waitq);
320         cfs_wait_event(ll_capa_thread.t_ctl_waitq,
321                        ll_capa_thread.t_flags & SVC_STOPPED);
322 }
323
324 struct obd_capa *ll_osscapa_get(struct inode *inode, __u64 opc)
325 {
326         struct ll_inode_info *lli = ll_i2info(inode);
327         struct obd_capa *ocapa;
328         int found = 0;
329
330         ENTRY;
331
332         if ((ll_i2sbi(inode)->ll_flags & LL_SBI_OSS_CAPA) == 0)
333                 RETURN(NULL);
334
335         LASSERT(opc == CAPA_OPC_OSS_WRITE || opc == CAPA_OPC_OSS_RW ||
336                 opc == CAPA_OPC_OSS_TRUNC);
337
338         cfs_spin_lock(&capa_lock);
339         cfs_list_for_each_entry(ocapa, &lli->lli_oss_capas, u.cli.lli_list) {
340                 if (capa_is_expired(ocapa))
341                         continue;
342                 if ((opc & CAPA_OPC_OSS_WRITE) &&
343                     capa_opc_supported(&ocapa->c_capa, CAPA_OPC_OSS_WRITE)) {
344                         found = 1;
345                         break;
346                 } else if ((opc & CAPA_OPC_OSS_READ) &&
347                            capa_opc_supported(&ocapa->c_capa,
348                                               CAPA_OPC_OSS_READ)) {
349                         found = 1;
350                         break;
351                 } else if ((opc & CAPA_OPC_OSS_TRUNC) &&
352                            capa_opc_supported(&ocapa->c_capa, opc)) {
353                         found = 1;
354                         break;
355                 }
356         }
357
358         if (found) {
359                 LASSERT(lu_fid_eq(capa_fid(&ocapa->c_capa),
360                                   ll_inode2fid(inode)));
361                 LASSERT(ocapa->c_site == CAPA_SITE_CLIENT);
362
363                 capa_get(ocapa);
364
365                 DEBUG_CAPA(D_SEC, &ocapa->c_capa, "found client");
366         } else {
367                 ocapa = NULL;
368
369                 if (cfs_atomic_read(&ll_capa_debug)) {
370                         CERROR("no capability for "DFID" opc "LPX64"\n",
371                                PFID(&lli->lli_fid), opc);
372                         cfs_atomic_set(&ll_capa_debug, 0);
373                 }
374         }
375         cfs_spin_unlock(&capa_lock);
376
377         RETURN(ocapa);
378 }
379 EXPORT_SYMBOL(ll_osscapa_get);
380
381 struct obd_capa *ll_mdscapa_get(struct inode *inode)
382 {
383         struct ll_inode_info *lli = ll_i2info(inode);
384         struct obd_capa *ocapa;
385         ENTRY;
386
387         LASSERT(inode != NULL);
388
389         if ((ll_i2sbi(inode)->ll_flags & LL_SBI_MDS_CAPA) == 0)
390                 RETURN(NULL);
391
392         cfs_spin_lock(&capa_lock);
393         ocapa = capa_get(lli->lli_mds_capa);
394         cfs_spin_unlock(&capa_lock);
395         if (!ocapa && cfs_atomic_read(&ll_capa_debug)) {
396                 CERROR("no mds capability for "DFID"\n", PFID(&lli->lli_fid));
397                 cfs_atomic_set(&ll_capa_debug, 0);
398         }
399
400         RETURN(ocapa);
401 }
402
403 static struct obd_capa *do_add_mds_capa(struct inode *inode,
404                                         struct obd_capa *ocapa)
405 {
406         struct ll_inode_info *lli = ll_i2info(inode);
407         struct obd_capa *old = lli->lli_mds_capa;
408         struct lustre_capa *capa = &ocapa->c_capa;
409
410         if (!old) {
411                 ocapa->u.cli.inode = inode;
412                 lli->lli_mds_capa = ocapa;
413                 capa_count[CAPA_SITE_CLIENT]++;
414
415                 DEBUG_CAPA(D_SEC, capa, "add MDS");
416         } else {
417                 cfs_spin_lock(&old->c_lock);
418                 old->c_capa = *capa;
419                 cfs_spin_unlock(&old->c_lock);
420
421                 DEBUG_CAPA(D_SEC, capa, "update MDS");
422
423                 capa_put(ocapa);
424                 ocapa = old;
425         }
426         return ocapa;
427 }
428
429 static struct obd_capa *do_lookup_oss_capa(struct inode *inode, int opc)
430 {
431         struct ll_inode_info *lli = ll_i2info(inode);
432         struct obd_capa *ocapa;
433
434         /* inside capa_lock */
435         cfs_list_for_each_entry(ocapa, &lli->lli_oss_capas, u.cli.lli_list) {
436                 if ((capa_opc(&ocapa->c_capa) & opc) != opc)
437                         continue;
438
439                 LASSERT(lu_fid_eq(capa_fid(&ocapa->c_capa),
440                                   ll_inode2fid(inode)));
441                 LASSERT(ocapa->c_site == CAPA_SITE_CLIENT);
442
443                 DEBUG_CAPA(D_SEC, &ocapa->c_capa, "found client");
444                 return ocapa;
445         }
446
447         return NULL;
448 }
449
450 static inline void inode_add_oss_capa(struct inode *inode,
451                                       struct obd_capa *ocapa)
452 {
453         struct ll_inode_info *lli = ll_i2info(inode);
454         struct obd_capa *tmp;
455         cfs_list_t *next = NULL;
456
457         /* capa is sorted in lli_oss_capas so lookup can always find the
458          * latest one */
459         cfs_list_for_each_entry(tmp, &lli->lli_oss_capas, u.cli.lli_list) {
460                 if (cfs_time_after(ocapa->c_expiry, tmp->c_expiry)) {
461                         next = &tmp->u.cli.lli_list;
462                         break;
463                 }
464         }
465         LASSERT(&ocapa->u.cli.lli_list != next);
466         cfs_list_move_tail(&ocapa->u.cli.lli_list, next ?: &lli->lli_oss_capas);
467 }
468
469 static struct obd_capa *do_add_oss_capa(struct inode *inode,
470                                         struct obd_capa *ocapa)
471 {
472         struct obd_capa *old;
473         struct lustre_capa *capa = &ocapa->c_capa;
474
475         LASSERTF(S_ISREG(inode->i_mode),
476                  "inode has oss capa, but not regular file, mode: %d\n",
477                  inode->i_mode);
478
479         /* FIXME: can't replace it so easily with fine-grained opc */
480         old = do_lookup_oss_capa(inode, capa_opc(capa) & CAPA_OPC_OSS_ONLY);
481         if (!old) {
482                 ocapa->u.cli.inode = inode;
483                 CFS_INIT_LIST_HEAD(&ocapa->u.cli.lli_list);
484                 capa_count[CAPA_SITE_CLIENT]++;
485
486                 DEBUG_CAPA(D_SEC, capa, "add OSS");
487         } else {
488                 cfs_spin_lock(&old->c_lock);
489                 old->c_capa = *capa;
490                 cfs_spin_unlock(&old->c_lock);
491
492                 DEBUG_CAPA(D_SEC, capa, "update OSS");
493
494                 capa_put(ocapa);
495                 ocapa = old;
496         }
497
498         inode_add_oss_capa(inode, ocapa);
499         return ocapa;
500 }
501
502 struct obd_capa *ll_add_capa(struct inode *inode, struct obd_capa *ocapa)
503 {
504         cfs_spin_lock(&capa_lock);
505         ocapa = capa_for_mds(&ocapa->c_capa) ? do_add_mds_capa(inode, ocapa) :
506                                                do_add_oss_capa(inode, ocapa);
507
508         /* truncate capa won't renew */
509         if (ocapa->c_capa.lc_opc != CAPA_OPC_OSS_TRUNC) {
510                 set_capa_expiry(ocapa);
511                 cfs_list_del_init(&ocapa->c_list);
512                 sort_add_capa(ocapa, ll_capa_list);
513
514                 update_capa_timer(ocapa, capa_renewal_time(ocapa));
515         }
516
517         cfs_spin_unlock(&capa_lock);
518
519         cfs_atomic_set(&ll_capa_debug, 1);
520         return ocapa;
521 }
522
523 static inline void delay_capa_renew(struct obd_capa *oc, cfs_time_t delay)
524 {
525         /* NB: set a fake expiry for this capa to prevent it renew too soon */
526         oc->c_expiry = cfs_time_add(oc->c_expiry, cfs_time_seconds(delay));
527 }
528
529 int ll_update_capa(struct obd_capa *ocapa, struct lustre_capa *capa)
530 {
531         struct inode *inode = ocapa->u.cli.inode;
532         int rc = 0;
533         ENTRY;
534
535         LASSERT(ocapa);
536
537         if (IS_ERR(capa)) {
538                 /* set error code */
539                 rc = PTR_ERR(capa);
540                 cfs_spin_lock(&capa_lock);
541                 if (rc == -ENOENT) {
542                         DEBUG_CAPA(D_SEC, &ocapa->c_capa,
543                                    "renewal canceled because object removed");
544                         ll_capa_renewal_noent++;
545                 } else {
546                         ll_capa_renewal_failed++;
547
548                         /* failed capa won't be renewed any longer, but if -EIO,
549                          * client might be doing recovery, retry in 2 min. */
550                         if (rc == -EIO && !capa_is_expired(ocapa)) {
551                                 delay_capa_renew(ocapa, 120);
552                                 DEBUG_CAPA(D_ERROR, &ocapa->c_capa,
553                                            "renewal failed: -EIO, "
554                                            "retry in 2 mins");
555                                 ll_capa_renewal_retries++;
556                                 GOTO(retry, rc);
557                         } else {
558                                 DEBUG_CAPA(D_ERROR, &ocapa->c_capa,
559                                            "renewal failed(rc: %d) for", rc);
560                         }
561                 }
562
563                 cfs_list_del_init(&ocapa->c_list);
564                 sort_add_capa(ocapa, &ll_idle_capas);
565                 cfs_spin_unlock(&capa_lock);
566
567                 capa_put(ocapa);
568                 iput(inode);
569                 RETURN(rc);
570         }
571
572         cfs_spin_lock(&ocapa->c_lock);
573         LASSERT(!memcmp(&ocapa->c_capa, capa,
574                         offsetof(struct lustre_capa, lc_opc)));
575         ocapa->c_capa = *capa;
576         set_capa_expiry(ocapa);
577         cfs_spin_unlock(&ocapa->c_lock);
578
579         cfs_spin_lock(&capa_lock);
580         if (capa_for_oss(capa))
581                 inode_add_oss_capa(inode, ocapa);
582         DEBUG_CAPA(D_SEC, capa, "renew");
583         EXIT;
584 retry:
585         cfs_list_del_init(&ocapa->c_list);
586         sort_add_capa(ocapa, ll_capa_list);
587         update_capa_timer(ocapa, capa_renewal_time(ocapa));
588         cfs_spin_unlock(&capa_lock);
589
590         capa_put(ocapa);
591         iput(inode);
592         return rc;
593 }
594
595 void ll_capa_open(struct inode *inode)
596 {
597         struct ll_inode_info *lli = ll_i2info(inode);
598
599         if ((ll_i2sbi(inode)->ll_flags & (LL_SBI_MDS_CAPA | LL_SBI_OSS_CAPA))
600             == 0)
601                 return;
602
603         if (!S_ISREG(inode->i_mode))
604                 return;
605
606         cfs_atomic_inc(&lli->lli_open_count);
607 }
608
609 void ll_capa_close(struct inode *inode)
610 {
611         struct ll_inode_info *lli = ll_i2info(inode);
612
613         if ((ll_i2sbi(inode)->ll_flags & (LL_SBI_MDS_CAPA | LL_SBI_OSS_CAPA))
614             == 0)
615                 return;
616
617         if (!S_ISREG(inode->i_mode))
618                 return;
619
620         cfs_atomic_dec(&lli->lli_open_count);
621 }
622
623 /* delete CAPA_OPC_OSS_TRUNC only */
624 void ll_truncate_free_capa(struct obd_capa *ocapa)
625 {
626         if (!ocapa)
627                 return;
628
629         LASSERT(ocapa->c_capa.lc_opc & CAPA_OPC_OSS_TRUNC);
630         DEBUG_CAPA(D_SEC, &ocapa->c_capa, "free truncate");
631
632         /* release ref when find */
633         capa_put(ocapa);
634         if (likely(ocapa->c_capa.lc_opc == CAPA_OPC_OSS_TRUNC)) {
635                 cfs_spin_lock(&capa_lock);
636                 ll_delete_capa(ocapa);
637                 cfs_spin_unlock(&capa_lock);
638         }
639 }
640
641 void ll_clear_inode_capas(struct inode *inode)
642 {
643         struct ll_inode_info *lli = ll_i2info(inode);
644         struct obd_capa *ocapa, *tmp;
645
646         cfs_spin_lock(&capa_lock);
647         ocapa = lli->lli_mds_capa;
648         if (ocapa)
649                 ll_delete_capa(ocapa);
650
651         cfs_list_for_each_entry_safe(ocapa, tmp, &lli->lli_oss_capas,
652                                      u.cli.lli_list)
653                 ll_delete_capa(ocapa);
654         cfs_spin_unlock(&capa_lock);
655 }
656
657 void ll_print_capa_stat(struct ll_sb_info *sbi)
658 {
659         if (sbi->ll_flags & (LL_SBI_MDS_CAPA | LL_SBI_OSS_CAPA))
660                 LCONSOLE_INFO("Fid capabilities renewed: %llu\n"
661                               "Fid capabilities renewal ENOENT: %llu\n"
662                               "Fid capabilities failed to renew: %llu\n"
663                               "Fid capabilities renewal retries: %llu\n",
664                               ll_capa_renewed, ll_capa_renewal_noent,
665                               ll_capa_renewal_failed, ll_capa_renewal_retries);
666 }