4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2017, DDN Storage Corporation.
26 * Persistent Client Cache
28 * PCC is a new framework which provides a group of local cache on Lustre
29 * client side. It works in two modes: RW-PCC enables a read-write cache on the
30 * local SSDs of a single client; RO-PCC provides a read-only cache on the
31 * local SSDs of multiple clients. Less overhead is visible to the applications
32 * and network latencies and lock conflicts can be significantly reduced.
34 * For RW-PCC, no global namespace will be provided. Each client uses its own
35 * local storage as a cache for itself. Local file system is used to manage
36 * the data on local caches. Cached I/O is directed to local file system while
37 * normal I/O is directed to OSTs. RW-PCC uses HSM for data synchronization.
38 * It uses HSM copytool to restore file from local caches to Lustre OSTs. Each
39 * PCC has a copytool instance running with unique archive number. Any remote
40 * access from another Lustre client would trigger the data synchronization. If
41 * a client with RW-PCC goes offline, the cached data becomes inaccessible for
42 * other client temporarily. And after the RW-PCC client reboots and the
43 * copytool restarts, the data will be accessible again.
45 * Following is what will happen in different conditions for RW-PCC:
47 * > When file is being created on RW-PCC
49 * A normal HSM released file is created on MDT;
50 * An empty mirror file is created on local cache;
51 * The HSM status of the Lustre file will be set to archived and released;
52 * The archive number will be set to the proper value.
54 * > When file is being prefetched to RW-PCC
56 * An file is copied to the local cache;
57 * The HSM status of the Lustre file will be set to archived and released;
58 * The archive number will be set to the proper value.
60 * > When file is being accessed from PCC
62 * Data will be read directly from local cache;
63 * Metadata will be read from MDT, except file size;
64 * File size will be got from local cache.
66 * > When PCC cached file is being accessed on another client
68 * RW-PCC cached files are automatically restored when a process on another
69 * client tries to read or modify them. The corresponding I/O will block
70 * waiting for the released file to be restored. This is transparent to the
73 * For RW-PCC, when a file is being created, a rule-based policy is used to
74 * determine whether it will be cached. Rule-based caching of newly created
75 * files can determine which file can use a cache on PCC directly without any
78 * RW-PCC design can accelerate I/O intensive applications with one-to-one
79 * mappings between files and accessing clients. However, in several use cases,
80 * files will never be updated, but need to be read simultaneously from many
81 * clients. RO-PCC implements a read-only caching on Lustre clients using
82 * SSDs. RO-PCC is based on the same framework as RW-PCC, expect
83 * that no HSM mechanism is used.
85 * The main advantages to use this SSD cache on the Lustre clients via PCC
87 * - The I/O stack becomes much simpler for the cached data, as there is no
88 * interference with I/Os from other clients, which enables easier
89 * performance optimizations;
90 * - The requirements on the HW inside the client nodes are small, any kind of
91 * SSDs or even HDDs can be used as cache devices;
92 * - Caching reduces the pressure on the object storage targets (OSTs), as
93 * small or random I/Os can be regularized to big sequential I/Os and
94 * temporary files do not even need to be flushed to OSTs.
96 * PCC can accelerate applications with certain I/O patterns:
97 * - small-sized random writes (< 1MB) from a single client
98 * - repeated read of data that is larger than RAM
99 * - clients with high network latency
101 * Author: Li Xi <lixi@ddn.com>
102 * Author: Qian Yingjin <qian@ddn.com>
105 #define DEBUG_SUBSYSTEM S_LLITE
108 #include <linux/namei.h>
109 #include <linux/file.h>
110 #include <lustre_compat.h>
111 #include "llite_internal.h"
113 struct kmem_cache *pcc_inode_slab;
115 int pcc_super_init(struct pcc_super *super)
119 super->pccs_cred = cred = prepare_creds();
123 /* Never override disk quota limits or use reserved space */
124 cap_lower(cred->cap_effective, CAP_SYS_RESOURCE);
125 init_rwsem(&super->pccs_rw_sem);
126 INIT_LIST_HEAD(&super->pccs_datasets);
127 super->pccs_generation = 1;
132 /* Rule based auto caching */
133 static void pcc_id_list_free(struct list_head *id_list)
135 struct pcc_match_id *id, *n;
137 list_for_each_entry_safe(id, n, id_list, pmi_linkage) {
138 list_del_init(&id->pmi_linkage);
143 static void pcc_fname_list_free(struct list_head *fname_list)
145 struct pcc_match_fname *fname, *n;
147 list_for_each_entry_safe(fname, n, fname_list, pmf_linkage) {
148 OBD_FREE(fname->pmf_name, strlen(fname->pmf_name) + 1);
149 list_del_init(&fname->pmf_linkage);
154 static void pcc_expression_free(struct pcc_expression *expr)
156 LASSERT(expr->pe_field >= PCC_FIELD_UID &&
157 expr->pe_field < PCC_FIELD_MAX);
158 switch (expr->pe_field) {
161 case PCC_FIELD_PROJID:
162 pcc_id_list_free(&expr->pe_cond);
164 case PCC_FIELD_FNAME:
165 pcc_fname_list_free(&expr->pe_cond);
173 static void pcc_conjunction_free(struct pcc_conjunction *conjunction)
175 struct pcc_expression *expression, *n;
177 LASSERT(list_empty(&conjunction->pc_linkage));
178 list_for_each_entry_safe(expression, n,
179 &conjunction->pc_expressions,
181 list_del_init(&expression->pe_linkage);
182 pcc_expression_free(expression);
184 OBD_FREE_PTR(conjunction);
187 static void pcc_rule_conds_free(struct list_head *cond_list)
189 struct pcc_conjunction *conjunction, *n;
191 list_for_each_entry_safe(conjunction, n, cond_list, pc_linkage) {
192 list_del_init(&conjunction->pc_linkage);
193 pcc_conjunction_free(conjunction);
197 static void pcc_cmd_fini(struct pcc_cmd *cmd)
199 if (cmd->pccc_cmd == PCC_ADD_DATASET) {
200 if (!list_empty(&cmd->u.pccc_add.pccc_conds))
201 pcc_rule_conds_free(&cmd->u.pccc_add.pccc_conds);
202 if (cmd->u.pccc_add.pccc_conds_str)
203 OBD_FREE(cmd->u.pccc_add.pccc_conds_str,
204 strlen(cmd->u.pccc_add.pccc_conds_str) + 1);
208 #define PCC_DISJUNCTION_DELIM (",")
209 #define PCC_CONJUNCTION_DELIM ("&")
210 #define PCC_EXPRESSION_DELIM ("=")
213 pcc_fname_list_add(struct cfs_lstr *id, struct list_head *fname_list)
215 struct pcc_match_fname *fname;
217 OBD_ALLOC_PTR(fname);
221 OBD_ALLOC(fname->pmf_name, id->ls_len + 1);
222 if (fname->pmf_name == NULL) {
227 memcpy(fname->pmf_name, id->ls_str, id->ls_len);
228 list_add_tail(&fname->pmf_linkage, fname_list);
233 pcc_fname_list_parse(char *str, int len, struct list_head *fname_list)
243 INIT_LIST_HEAD(fname_list);
245 rc = cfs_gettok(&src, ' ', &res);
250 rc = pcc_fname_list_add(&res, fname_list);
255 pcc_fname_list_free(fname_list);
260 pcc_id_list_parse(char *str, struct list_head *id_list,
267 if (type != PCC_FIELD_UID && type != PCC_FIELD_GID &&
268 type != PCC_FIELD_PROJID)
271 INIT_LIST_HEAD(id_list);
274 struct pcc_match_id *id;
275 unsigned long id_val;
277 num = strsep(&str, " ");
280 rc = kstrtoul(num, 0, &id_val);
286 GOTO(out, rc = -ENOMEM);
289 list_add_tail(&id->pmi_linkage, id_list);
291 if (list_empty(id_list))
295 pcc_id_list_free(id_list);
300 pcc_expression_parse(char *str, struct list_head *cond_list)
302 struct pcc_expression *expr;
311 field = strim(strsep(&str, PCC_EXPRESSION_DELIM));
313 /* No LHS or no '=' */
314 GOTO(out, rc = -EINVAL);
315 str = skip_spaces(str);
317 if (str[0] != '{' || str[len - 1] != '}')
318 GOTO(out, rc = -EINVAL);
320 /* Skip '{' and '}' */
325 if (strcmp(field, "uid") == 0) {
326 if (pcc_id_list_parse(str,
329 GOTO(out, rc = -EINVAL);
330 expr->pe_field = PCC_FIELD_UID;
331 } else if (strcmp(field, "gid") == 0) {
332 if (pcc_id_list_parse(str,
335 GOTO(out, rc = -EINVAL);
336 expr->pe_field = PCC_FIELD_GID;
337 } else if (strcmp(field, "projid") == 0) {
338 if (pcc_id_list_parse(str,
340 PCC_FIELD_PROJID) < 0)
341 GOTO(out, rc = -EINVAL);
342 expr->pe_field = PCC_FIELD_PROJID;
343 } else if (strcmp(field, "fname") == 0) {
344 if (pcc_fname_list_parse(str, len,
346 GOTO(out, rc = -EINVAL);
347 expr->pe_field = PCC_FIELD_FNAME;
349 GOTO(out, rc = -EINVAL);
352 list_add_tail(&expr->pe_linkage, cond_list);
360 pcc_conjunction_parse(char *str, struct list_head *cond_list)
362 struct pcc_conjunction *conjunction;
365 OBD_ALLOC_PTR(conjunction);
366 if (conjunction == NULL)
369 INIT_LIST_HEAD(&conjunction->pc_expressions);
370 list_add_tail(&conjunction->pc_linkage, cond_list);
372 while (rc == 0 && str) {
373 char *expr = strsep(&str, PCC_CONJUNCTION_DELIM);
375 rc = pcc_expression_parse(expr, &conjunction->pc_expressions);
380 static int pcc_conds_parse(char *orig, struct list_head *cond_list)
385 orig = kstrdup(orig, GFP_KERNEL);
390 INIT_LIST_HEAD(cond_list);
391 while (rc == 0 && str) {
392 char *term = strsep(&str, PCC_DISJUNCTION_DELIM);
394 rc = pcc_conjunction_parse(term, cond_list);
400 static int pcc_id_parse(struct pcc_cmd *cmd, const char *id)
404 OBD_ALLOC(cmd->u.pccc_add.pccc_conds_str, strlen(id) + 1);
405 if (cmd->u.pccc_add.pccc_conds_str == NULL)
408 memcpy(cmd->u.pccc_add.pccc_conds_str, id, strlen(id));
410 rc = pcc_conds_parse(cmd->u.pccc_add.pccc_conds_str,
411 &cmd->u.pccc_add.pccc_conds);
419 pcc_parse_value_pair(struct pcc_cmd *cmd, char *buffer)
426 key = strsep(&val, "=");
427 if (val == NULL || strlen(val) == 0)
430 /* Key of the value pair */
431 if (strcmp(key, "rwid") == 0) {
432 rc = kstrtoul(val, 10, &id);
437 cmd->u.pccc_add.pccc_rwid = id;
438 } else if (strcmp(key, "roid") == 0) {
439 rc = kstrtoul(val, 10, &id);
444 cmd->u.pccc_add.pccc_roid = id;
445 } else if (strcmp(key, "auto_attach") == 0) {
446 rc = kstrtoul(val, 10, &id);
450 cmd->u.pccc_add.pccc_flags &= ~PCC_DATASET_AUTO_ATTACH;
451 } else if (strcmp(key, "open_attach") == 0) {
452 rc = kstrtoul(val, 10, &id);
456 cmd->u.pccc_add.pccc_flags &= ~PCC_DATASET_OPEN_ATTACH;
457 } else if (strcmp(key, "io_attach") == 0) {
458 rc = kstrtoul(val, 10, &id);
462 cmd->u.pccc_add.pccc_flags &= ~PCC_DATASET_IO_ATTACH;
463 } else if (strcmp(key, "stat_attach") == 0) {
464 rc = kstrtoul(val, 10, &id);
468 cmd->u.pccc_add.pccc_flags &= ~PCC_DATASET_STAT_ATTACH;
469 } else if (strcmp(key, "rwpcc") == 0) {
470 rc = kstrtoul(val, 10, &id);
474 cmd->u.pccc_add.pccc_flags |= PCC_DATASET_RWPCC;
475 } else if (strcmp(key, "ropcc") == 0) {
476 rc = kstrtoul(val, 10, &id);
480 cmd->u.pccc_add.pccc_flags |= PCC_DATASET_ROPCC;
489 pcc_parse_value_pairs(struct pcc_cmd *cmd, char *buffer)
495 switch (cmd->pccc_cmd) {
496 case PCC_ADD_DATASET:
497 /* Enable auto attach by default */
498 cmd->u.pccc_add.pccc_flags |= PCC_DATASET_AUTO_ATTACH;
500 case PCC_DEL_DATASET:
508 while (val != NULL && strlen(val) != 0) {
509 token = strsep(&val, " ");
510 rc = pcc_parse_value_pair(cmd, token);
515 switch (cmd->pccc_cmd) {
516 case PCC_ADD_DATASET:
517 if (cmd->u.pccc_add.pccc_flags & PCC_DATASET_RWPCC &&
518 cmd->u.pccc_add.pccc_flags & PCC_DATASET_ROPCC)
521 * By default, a PCC backend can provide caching service for
522 * both RW-PCC and RO-PCC.
524 if ((cmd->u.pccc_add.pccc_flags & PCC_DATASET_PCC_ALL) == 0)
525 cmd->u.pccc_add.pccc_flags |= PCC_DATASET_PCC_ALL;
527 /* For RW-PCC, the value of @rwid must be non zero. */
528 if (cmd->u.pccc_add.pccc_flags & PCC_DATASET_RWPCC &&
529 cmd->u.pccc_add.pccc_rwid == 0)
533 case PCC_DEL_DATASET:
543 pcc_dataset_rule_fini(struct pcc_match_rule *rule)
545 if (!list_empty(&rule->pmr_conds))
546 pcc_rule_conds_free(&rule->pmr_conds);
547 LASSERT(rule->pmr_conds_str != NULL);
548 OBD_FREE(rule->pmr_conds_str, strlen(rule->pmr_conds_str) + 1);
552 pcc_dataset_rule_init(struct pcc_match_rule *rule, struct pcc_cmd *cmd)
556 LASSERT(cmd->u.pccc_add.pccc_conds_str);
557 OBD_ALLOC(rule->pmr_conds_str,
558 strlen(cmd->u.pccc_add.pccc_conds_str) + 1);
559 if (rule->pmr_conds_str == NULL)
562 memcpy(rule->pmr_conds_str,
563 cmd->u.pccc_add.pccc_conds_str,
564 strlen(cmd->u.pccc_add.pccc_conds_str));
566 INIT_LIST_HEAD(&rule->pmr_conds);
567 if (!list_empty(&cmd->u.pccc_add.pccc_conds))
568 rc = pcc_conds_parse(rule->pmr_conds_str,
572 pcc_dataset_rule_fini(rule);
579 pcc_id_list_match(struct list_head *id_list, __u32 id_val)
581 struct pcc_match_id *id;
583 list_for_each_entry(id, id_list, pmi_linkage) {
584 if (id->pmi_id == id_val)
591 cfs_match_wildcard(const char *pattern, const char *content)
593 if (*pattern == '\0' && *content == '\0')
596 if (*pattern == '*' && *(pattern + 1) != '\0' && *content == '\0')
599 while (*pattern == *content) {
602 if (*pattern == '\0' && *content == '\0')
605 if (*pattern == '*' && *(pattern + 1) != '\0' &&
611 return (cfs_match_wildcard(pattern + 1, content) ||
612 cfs_match_wildcard(pattern, content + 1));
618 pcc_fname_list_match(struct list_head *fname_list, const char *name)
620 struct pcc_match_fname *fname;
622 list_for_each_entry(fname, fname_list, pmf_linkage) {
623 if (cfs_match_wildcard(fname->pmf_name, name))
630 pcc_expression_match(struct pcc_expression *expr, struct pcc_matcher *matcher)
632 switch (expr->pe_field) {
634 return pcc_id_list_match(&expr->pe_cond, matcher->pm_uid);
636 return pcc_id_list_match(&expr->pe_cond, matcher->pm_gid);
637 case PCC_FIELD_PROJID:
638 return pcc_id_list_match(&expr->pe_cond, matcher->pm_projid);
639 case PCC_FIELD_FNAME:
640 return pcc_fname_list_match(&expr->pe_cond,
641 matcher->pm_name->name);
648 pcc_conjunction_match(struct pcc_conjunction *conjunction,
649 struct pcc_matcher *matcher)
651 struct pcc_expression *expr;
654 list_for_each_entry(expr, &conjunction->pc_expressions, pe_linkage) {
655 matched = pcc_expression_match(expr, matcher);
664 pcc_cond_match(struct pcc_match_rule *rule, struct pcc_matcher *matcher)
666 struct pcc_conjunction *conjunction;
669 list_for_each_entry(conjunction, &rule->pmr_conds, pc_linkage) {
670 matched = pcc_conjunction_match(conjunction, matcher);
679 pcc_dataset_match_get(struct pcc_super *super, struct pcc_matcher *matcher)
681 struct pcc_dataset *dataset;
682 struct pcc_dataset *selected = NULL;
684 down_read(&super->pccs_rw_sem);
685 list_for_each_entry(dataset, &super->pccs_datasets, pccd_linkage) {
686 if (!(dataset->pccd_flags & PCC_DATASET_RWPCC))
689 if (pcc_cond_match(&dataset->pccd_rule, matcher)) {
690 atomic_inc(&dataset->pccd_refcount);
695 up_read(&super->pccs_rw_sem);
697 CDEBUG(D_CACHE, "PCC create, matched %s - %d:%d:%d:%s\n",
698 dataset->pccd_rule.pmr_conds_str,
699 matcher->pm_uid, matcher->pm_gid,
700 matcher->pm_projid, matcher->pm_name->name);
706 * pcc_dataset_add - Add a Cache policy to control which files need be
707 * cached and where it will be cached.
709 * @super: superblock of pcc
713 pcc_dataset_add(struct pcc_super *super, struct pcc_cmd *cmd)
715 char *pathname = cmd->pccc_pathname;
716 struct pcc_dataset *dataset;
717 struct pcc_dataset *tmp;
721 OBD_ALLOC_PTR(dataset);
725 rc = kern_path(pathname, LOOKUP_DIRECTORY, &dataset->pccd_path);
727 OBD_FREE_PTR(dataset);
730 strncpy(dataset->pccd_pathname, pathname, PATH_MAX);
731 dataset->pccd_rwid = cmd->u.pccc_add.pccc_rwid;
732 dataset->pccd_roid = cmd->u.pccc_add.pccc_roid;
733 dataset->pccd_flags = cmd->u.pccc_add.pccc_flags;
734 atomic_set(&dataset->pccd_refcount, 1);
736 rc = pcc_dataset_rule_init(&dataset->pccd_rule, cmd);
738 pcc_dataset_put(dataset);
742 down_write(&super->pccs_rw_sem);
743 list_for_each_entry(tmp, &super->pccs_datasets, pccd_linkage) {
744 if (strcmp(tmp->pccd_pathname, pathname) == 0 ||
745 (dataset->pccd_rwid != 0 &&
746 dataset->pccd_rwid == tmp->pccd_rwid) ||
747 (dataset->pccd_roid != 0 &&
748 dataset->pccd_roid == tmp->pccd_roid)) {
754 list_add(&dataset->pccd_linkage, &super->pccs_datasets);
755 up_write(&super->pccs_rw_sem);
758 pcc_dataset_put(dataset);
765 static struct pcc_dataset *
766 pcc_dataset_get(struct pcc_super *super, enum lu_pcc_type type, __u32 id)
768 struct pcc_dataset *dataset;
769 struct pcc_dataset *selected = NULL;
775 * archive ID (read-write ID) or read-only ID is unique in the list,
776 * we just return last added one as first priority.
778 down_read(&super->pccs_rw_sem);
779 list_for_each_entry(dataset, &super->pccs_datasets, pccd_linkage) {
780 if (type == LU_PCC_READWRITE && (dataset->pccd_rwid != id ||
781 !(dataset->pccd_flags & PCC_DATASET_RWPCC)))
783 atomic_inc(&dataset->pccd_refcount);
787 up_read(&super->pccs_rw_sem);
789 CDEBUG(D_CACHE, "matched id %u, PCC mode %d\n", id, type);
795 pcc_dataset_put(struct pcc_dataset *dataset)
797 if (atomic_dec_and_test(&dataset->pccd_refcount)) {
798 pcc_dataset_rule_fini(&dataset->pccd_rule);
799 path_put(&dataset->pccd_path);
800 OBD_FREE_PTR(dataset);
805 pcc_dataset_del(struct pcc_super *super, char *pathname)
807 struct list_head *l, *tmp;
808 struct pcc_dataset *dataset;
811 down_write(&super->pccs_rw_sem);
812 list_for_each_safe(l, tmp, &super->pccs_datasets) {
813 dataset = list_entry(l, struct pcc_dataset, pccd_linkage);
814 if (strcmp(dataset->pccd_pathname, pathname) == 0) {
815 list_del_init(&dataset->pccd_linkage);
816 pcc_dataset_put(dataset);
817 super->pccs_generation++;
822 up_write(&super->pccs_rw_sem);
827 pcc_dataset_dump(struct pcc_dataset *dataset, struct seq_file *m)
829 seq_printf(m, "%s:\n", dataset->pccd_pathname);
830 seq_printf(m, " rwid: %u\n", dataset->pccd_rwid);
831 seq_printf(m, " flags: %x\n", dataset->pccd_flags);
832 seq_printf(m, " autocache: %s\n", dataset->pccd_rule.pmr_conds_str);
836 pcc_super_dump(struct pcc_super *super, struct seq_file *m)
838 struct pcc_dataset *dataset;
840 down_read(&super->pccs_rw_sem);
841 list_for_each_entry(dataset, &super->pccs_datasets, pccd_linkage) {
842 pcc_dataset_dump(dataset, m);
844 up_read(&super->pccs_rw_sem);
848 static void pcc_remove_datasets(struct pcc_super *super)
850 struct pcc_dataset *dataset, *tmp;
852 down_write(&super->pccs_rw_sem);
853 list_for_each_entry_safe(dataset, tmp,
854 &super->pccs_datasets, pccd_linkage) {
855 list_del(&dataset->pccd_linkage);
856 pcc_dataset_put(dataset);
858 super->pccs_generation++;
859 up_write(&super->pccs_rw_sem);
862 void pcc_super_fini(struct pcc_super *super)
864 pcc_remove_datasets(super);
865 put_cred(super->pccs_cred);
868 static bool pathname_is_valid(const char *pathname)
870 /* Needs to be absolute path */
871 if (pathname == NULL || strlen(pathname) == 0 ||
872 strlen(pathname) >= PATH_MAX || pathname[0] != '/')
877 static struct pcc_cmd *
878 pcc_cmd_parse(char *buffer, unsigned long count)
880 static struct pcc_cmd *cmd;
887 GOTO(out, rc = -ENOMEM);
889 /* clear all setting */
890 if (strncmp(buffer, "clear", 5) == 0) {
891 cmd->pccc_cmd = PCC_CLEAR_ALL;
896 token = strsep(&val, " ");
897 if (val == NULL || strlen(val) == 0)
898 GOTO(out_free_cmd, rc = -EINVAL);
900 /* Type of the command */
901 if (strcmp(token, "add") == 0)
902 cmd->pccc_cmd = PCC_ADD_DATASET;
903 else if (strcmp(token, "del") == 0)
904 cmd->pccc_cmd = PCC_DEL_DATASET;
906 GOTO(out_free_cmd, rc = -EINVAL);
908 /* Pathname of the dataset */
909 token = strsep(&val, " ");
910 if ((val == NULL && cmd->pccc_cmd != PCC_DEL_DATASET) ||
911 !pathname_is_valid(token))
912 GOTO(out_free_cmd, rc = -EINVAL);
913 cmd->pccc_pathname = token;
915 if (cmd->pccc_cmd == PCC_ADD_DATASET) {
919 val = strrchr(token, '}');
921 GOTO(out_free_cmd, rc = -EINVAL);
927 } else if (*val == ' ') {
931 GOTO(out_free_cmd, rc = -EINVAL);
934 rc = pcc_id_parse(cmd, token);
936 GOTO(out_free_cmd, rc);
938 rc = pcc_parse_value_pairs(cmd, val);
940 GOTO(out_cmd_fini, rc = -EINVAL);
953 int pcc_cmd_handle(char *buffer, unsigned long count,
954 struct pcc_super *super)
959 cmd = pcc_cmd_parse(buffer, count);
963 switch (cmd->pccc_cmd) {
964 case PCC_ADD_DATASET:
965 rc = pcc_dataset_add(super, cmd);
967 case PCC_DEL_DATASET:
968 rc = pcc_dataset_del(super, cmd->pccc_pathname);
971 pcc_remove_datasets(super);
983 static inline void pcc_inode_lock(struct inode *inode)
985 mutex_lock(&ll_i2info(inode)->lli_pcc_lock);
988 static inline void pcc_inode_unlock(struct inode *inode)
990 mutex_unlock(&ll_i2info(inode)->lli_pcc_lock);
993 static void pcc_inode_init(struct pcc_inode *pcci, struct ll_inode_info *lli)
995 pcci->pcci_lli = lli;
996 lli->lli_pcc_inode = pcci;
997 atomic_set(&pcci->pcci_refcount, 0);
998 pcci->pcci_type = LU_PCC_NONE;
999 pcci->pcci_layout_gen = CL_LAYOUT_GEN_NONE;
1000 atomic_set(&pcci->pcci_active_ios, 0);
1001 init_waitqueue_head(&pcci->pcci_waitq);
1004 static void pcc_inode_fini(struct pcc_inode *pcci)
1006 struct ll_inode_info *lli = pcci->pcci_lli;
1008 path_put(&pcci->pcci_path);
1009 pcci->pcci_type = LU_PCC_NONE;
1010 OBD_SLAB_FREE_PTR(pcci, pcc_inode_slab);
1011 lli->lli_pcc_inode = NULL;
1014 static void pcc_inode_get(struct pcc_inode *pcci)
1016 atomic_inc(&pcci->pcci_refcount);
1019 static void pcc_inode_put(struct pcc_inode *pcci)
1021 if (atomic_dec_and_test(&pcci->pcci_refcount))
1022 pcc_inode_fini(pcci);
1025 void pcc_inode_free(struct inode *inode)
1027 struct pcc_inode *pcci = ll_i2pcci(inode);
1030 WARN_ON(atomic_read(&pcci->pcci_refcount) > 1);
1031 pcc_inode_put(pcci);
1037 * As Andreas suggested, we'd better use new layout to
1039 * (fid->f_oid >> 16 & oxFFFF)/FID
1041 #define PCC_DATASET_MAX_PATH (6 * 5 + FID_NOBRACE_LEN + 1)
1042 static int pcc_fid2dataset_path(char *buf, int sz, struct lu_fid *fid)
1044 return scnprintf(buf, sz, "%04x/%04x/%04x/%04x/%04x/%04x/"
1046 (fid)->f_oid & 0xFFFF,
1047 (fid)->f_oid >> 16 & 0xFFFF,
1048 (unsigned int)((fid)->f_seq & 0xFFFF),
1049 (unsigned int)((fid)->f_seq >> 16 & 0xFFFF),
1050 (unsigned int)((fid)->f_seq >> 32 & 0xFFFF),
1051 (unsigned int)((fid)->f_seq >> 48 & 0xFFFF),
1055 static inline const struct cred *pcc_super_cred(struct super_block *sb)
1057 return ll_s2sbi(sb)->ll_pcc_super.pccs_cred;
1060 void pcc_file_init(struct pcc_file *pccf)
1062 pccf->pccf_file = NULL;
1063 pccf->pccf_type = LU_PCC_NONE;
1066 static inline bool pcc_auto_attach_enabled(enum pcc_dataset_flags flags,
1067 enum pcc_io_type iot)
1069 if (iot == PIT_OPEN)
1070 return flags & PCC_DATASET_OPEN_ATTACH;
1071 if (iot == PIT_GETATTR)
1072 return flags & PCC_DATASET_STAT_ATTACH;
1074 return flags & PCC_DATASET_AUTO_ATTACH;
1077 static const char pcc_xattr_layout[] = XATTR_USER_PREFIX "PCC.layout";
1079 static int pcc_layout_xattr_set(struct pcc_inode *pcci, __u32 gen)
1081 struct dentry *pcc_dentry = pcci->pcci_path.dentry;
1082 struct ll_inode_info *lli = pcci->pcci_lli;
1087 if (!(lli->lli_pcc_dsflags & PCC_DATASET_AUTO_ATTACH))
1090 rc = ll_vfs_setxattr(pcc_dentry, pcc_dentry->d_inode, pcc_xattr_layout,
1091 &gen, sizeof(gen), 0);
1096 static int pcc_get_layout_info(struct inode *inode, struct cl_layout *clt)
1099 struct ll_inode_info *lli = ll_i2info(inode);
1108 env = cl_env_get(&refcheck);
1110 RETURN(PTR_ERR(env));
1112 rc = cl_object_layout_get(env, lli->lli_clob, clt);
1114 CDEBUG(D_INODE, "Cannot get layout for "DFID"\n",
1115 PFID(ll_inode2fid(inode)));
1117 cl_env_put(env, &refcheck);
1118 RETURN(rc < 0 ? rc : 0);
1121 /* Must be called with pcci->pcci_lock held */
1122 static void pcc_inode_attach_init(struct pcc_dataset *dataset,
1123 struct pcc_inode *pcci,
1124 struct dentry *dentry,
1125 enum lu_pcc_type type)
1127 pcci->pcci_path.mnt = mntget(dataset->pccd_path.mnt);
1128 pcci->pcci_path.dentry = dentry;
1129 LASSERT(atomic_read(&pcci->pcci_refcount) == 0);
1130 atomic_set(&pcci->pcci_refcount, 1);
1131 pcci->pcci_type = type;
1132 pcci->pcci_attr_valid = false;
1135 static inline void pcc_inode_dsflags_set(struct ll_inode_info *lli,
1136 struct pcc_dataset *dataset)
1138 lli->lli_pcc_generation = ll_info2pccs(lli)->pccs_generation;
1139 lli->lli_pcc_dsflags = dataset->pccd_flags;
1142 static void pcc_inode_attach_set(struct pcc_super *super,
1143 struct pcc_dataset *dataset,
1144 struct ll_inode_info *lli,
1145 struct pcc_inode *pcci,
1146 struct dentry *dentry,
1147 enum lu_pcc_type type)
1149 pcc_inode_init(pcci, lli);
1150 pcc_inode_attach_init(dataset, pcci, dentry, type);
1151 down_read(&super->pccs_rw_sem);
1152 pcc_inode_dsflags_set(lli, dataset);
1153 up_read(&super->pccs_rw_sem);
1156 static inline void pcc_layout_gen_set(struct pcc_inode *pcci,
1159 pcci->pcci_layout_gen = gen;
1162 static inline bool pcc_inode_has_layout(struct pcc_inode *pcci)
1164 return pcci->pcci_layout_gen != CL_LAYOUT_GEN_NONE;
1167 static struct dentry *pcc_lookup(struct dentry *base, char *pathname)
1169 char *ptr = NULL, *component;
1170 struct dentry *parent;
1171 struct dentry *child = ERR_PTR(-ENOENT);
1175 /* move past any initial '/' to the start of the first path component*/
1179 /* store the start of the first path component */
1182 parent = dget(base);
1184 /* find the start of the next component - if we don't find it,
1185 * the current component is the last component
1187 ptr = strchr(ptr, '/');
1188 /* put a NUL char in place of the '/' before the next compnent
1189 * so we can treat this component as a string; note the full
1190 * path string is NUL terminated to this is not needed for the
1196 /* look up the current component */
1197 inode_lock(parent->d_inode);
1198 child = lookup_one_len(component, parent, strlen(component));
1199 inode_unlock(parent->d_inode);
1201 /* repair the path string: put '/' back in place of the NUL */
1207 if (IS_ERR_OR_NULL(child))
1210 /* we may find a cached negative dentry */
1211 if (!d_is_positive(child)) {
1217 /* descend in to the next level of the path */
1220 /* move the pointer past the '/' to the next component */
1226 /* NULL child means we didn't find anything */
1228 child = ERR_PTR(-ENOENT);
1233 static int pcc_try_dataset_attach(struct inode *inode, __u32 gen,
1234 enum lu_pcc_type type,
1235 struct pcc_dataset *dataset,
1238 struct ll_inode_info *lli = ll_i2info(inode);
1239 struct pcc_inode *pcci = lli->lli_pcc_inode;
1240 const struct cred *old_cred;
1241 struct dentry *pcc_dentry = NULL;
1242 char pathname[PCC_DATASET_MAX_PATH];
1248 if (type == LU_PCC_READWRITE &&
1249 !(dataset->pccd_flags & PCC_DATASET_RWPCC))
1252 rc = pcc_fid2dataset_path(pathname, PCC_DATASET_MAX_PATH,
1255 old_cred = override_creds(pcc_super_cred(inode->i_sb));
1256 pcc_dentry = pcc_lookup(dataset->pccd_path.dentry, pathname);
1257 if (IS_ERR(pcc_dentry)) {
1258 rc = PTR_ERR(pcc_dentry);
1259 CDEBUG(D_CACHE, "%s: path lookup error on "DFID":%s: rc = %d\n",
1260 ll_i2sbi(inode)->ll_fsname, PFID(&lli->lli_fid),
1262 /* ignore this error */
1266 rc = ll_vfs_getxattr(pcc_dentry, pcc_dentry->d_inode, pcc_xattr_layout,
1267 &pcc_gen, sizeof(pcc_gen));
1269 /* ignore this error */
1270 GOTO(out_put_pcc_dentry, rc = 0);
1273 /* The file is still valid cached in PCC, attach it immediately. */
1274 if (pcc_gen == gen) {
1275 CDEBUG(D_CACHE, DFID" L.Gen (%d) consistent, auto attached.\n",
1276 PFID(&lli->lli_fid), gen);
1278 OBD_SLAB_ALLOC_PTR_GFP(pcci, pcc_inode_slab, GFP_NOFS);
1280 GOTO(out_put_pcc_dentry, rc = -ENOMEM);
1282 pcc_inode_init(pcci, lli);
1284 pcc_inode_attach_init(dataset, pcci, pcc_dentry, type);
1287 * This happened when a file was once attached into
1288 * PCC, and some processes keep this file opened
1289 * (pcci->refcount > 1) and corresponding PCC file
1290 * without any I/O activity, and then this file was
1291 * detached by the manual detach command or the
1292 * revocation of the layout lock (i.e. cached LRU lock
1295 pcc_inode_get(pcci);
1296 pcci->pcci_type = type;
1298 pcc_inode_dsflags_set(lli, dataset);
1299 pcc_layout_gen_set(pcci, gen);
1305 revert_creds(old_cred);
1309 static int pcc_try_datasets_attach(struct inode *inode, enum pcc_io_type iot,
1310 __u32 gen, enum lu_pcc_type type,
1313 struct pcc_super *super = &ll_i2sbi(inode)->ll_pcc_super;
1314 struct ll_inode_info *lli = ll_i2info(inode);
1315 struct pcc_dataset *dataset = NULL, *tmp;
1320 down_read(&super->pccs_rw_sem);
1321 list_for_each_entry_safe(dataset, tmp,
1322 &super->pccs_datasets, pccd_linkage) {
1323 if (!pcc_auto_attach_enabled(dataset->pccd_flags, iot))
1326 rc = pcc_try_dataset_attach(inode, gen, type, dataset, cached);
1327 if (rc < 0 || (!rc && *cached))
1332 * Update the saved dataset flags for the inode accordingly if failed.
1334 if (!rc && !*cached) {
1336 * Currently auto attach strategy for a PCC backend is
1337 * unchangeable once once it was added into the PCC datasets on
1338 * a client as the support to change auto attach strategy is
1339 * not implemented yet.
1342 * If tried to attach from one PCC backend:
1343 * @lli_pcc_generation > 0:
1344 * 1) The file was once attached into PCC, but now the
1345 * corresponding PCC backend should be removed from the client;
1346 * 2) The layout generation was changed, the data has been
1348 * 3) The corresponding PCC copy is not existed on PCC
1349 * @lli_pcc_generation == 0:
1350 * The file is never attached into PCC but in a HSM released
1351 * state, or once attached into PCC but the inode was evicted
1352 * from icache later.
1353 * Set the saved dataset flags with PCC_DATASET_NONE. Then this
1354 * file will skip from the candidates to try auto attach until
1355 * the file is attached into PCC again.
1357 * If the file was never attached into PCC, or once attached but
1358 * its inode was evicted from icache (lli_pcc_generation == 0),
1359 * or the corresponding dataset was removed from the client,
1360 * set the saved dataset flags with PCC_DATASET_NONE.
1362 * TODO: If the file was once attached into PCC but not try to
1363 * auto attach due to the change of the configuration parameters
1364 * for this dataset (i.e. change from auto attach enabled to
1365 * auto attach disabled for this dataset), update the saved
1366 * dataset flags with the found one.
1368 lli->lli_pcc_dsflags = PCC_DATASET_NONE;
1370 up_read(&super->pccs_rw_sem);
1376 * TODO: For RW-PCC, it is desirable to store HSM info as a layout (LU-10606).
1377 * Thus the client can get archive ID from the layout directly. When try to
1378 * attach the file automatically which is in HSM released state (according to
1379 * LOV_PATTERN_F_RELEASED in the layout), it can determine whether the file is
1380 * valid cached on PCC more precisely according to the @rwid (archive ID) in
1381 * the PCC dataset and the archive ID in HSM attrs.
1383 static int pcc_try_auto_attach(struct inode *inode, bool *cached,
1384 enum pcc_io_type iot)
1386 struct pcc_super *super = &ll_i2sbi(inode)->ll_pcc_super;
1387 struct cl_layout clt = {
1389 .cl_is_released = false,
1391 struct ll_inode_info *lli = ll_i2info(inode);
1398 * Quick check whether there is PCC device.
1400 if (list_empty(&super->pccs_datasets))
1404 * The file layout lock was cancelled. And this open does not
1405 * obtain valid layout lock from MDT (i.e. the file is being
1408 if (iot == PIT_OPEN) {
1409 if (ll_layout_version_get(lli) == CL_LAYOUT_GEN_NONE)
1412 rc = ll_layout_refresh(inode, &gen);
1417 rc = pcc_get_layout_info(inode, &clt);
1421 if (iot != PIT_OPEN && gen != clt.cl_layout_gen) {
1422 CDEBUG(D_CACHE, DFID" layout changed from %d to %d.\n",
1423 PFID(ll_inode2fid(inode)), gen, clt.cl_layout_gen);
1427 if (clt.cl_is_released)
1428 rc = pcc_try_datasets_attach(inode, iot, clt.cl_layout_gen,
1429 LU_PCC_READWRITE, cached);
1434 static inline bool pcc_may_auto_attach(struct inode *inode,
1435 enum pcc_io_type iot)
1437 struct ll_inode_info *lli = ll_i2info(inode);
1438 struct pcc_super *super = ll_i2pccs(inode);
1440 /* Known the file was not in any PCC backend. */
1441 if (lli->lli_pcc_dsflags & PCC_DATASET_NONE)
1445 * lli_pcc_generation == 0 means that the file was never attached into
1446 * PCC, or may be once attached into PCC but detached as the inode is
1447 * evicted from icache (i.e. "echo 3 > /proc/sys/vm/drop_caches" or
1448 * icache shrinking due to the memory pressure), which will cause the
1449 * file detach from PCC when releasing the inode from icache.
1450 * In either case, we still try to attach.
1452 /* lli_pcc_generation == 0, or the PCC setting was changed,
1453 * or there is no PCC setup on the client and the try will return
1454 * immediately in pcc_try_auto_attach().
1456 if (super->pccs_generation != lli->lli_pcc_generation)
1459 /* The cached setting @lli_pcc_dsflags is valid */
1460 if (iot == PIT_OPEN)
1461 return lli->lli_pcc_dsflags & PCC_DATASET_OPEN_ATTACH;
1463 if (iot == PIT_GETATTR)
1464 return lli->lli_pcc_dsflags & PCC_DATASET_STAT_ATTACH;
1466 return lli->lli_pcc_dsflags & PCC_DATASET_IO_ATTACH;
1469 int pcc_file_open(struct inode *inode, struct file *file)
1471 struct pcc_inode *pcci;
1472 struct ll_inode_info *lli = ll_i2info(inode);
1473 struct ll_file_data *fd = file->private_data;
1474 struct pcc_file *pccf = &fd->fd_pcc_file;
1475 struct file *pcc_file;
1477 bool cached = false;
1482 if (!S_ISREG(inode->i_mode))
1485 if (IS_ENCRYPTED(inode))
1488 pcc_inode_lock(inode);
1489 pcci = ll_i2pcci(inode);
1491 if (lli->lli_pcc_state & PCC_STATE_FL_ATTACHING)
1492 GOTO(out_unlock, rc = 0);
1494 if (!pcci || !pcc_inode_has_layout(pcci)) {
1495 if (pcc_may_auto_attach(inode, PIT_OPEN))
1496 rc = pcc_try_auto_attach(inode, &cached, PIT_OPEN);
1498 if (rc < 0 || !cached)
1499 GOTO(out_unlock, rc);
1502 pcci = ll_i2pcci(inode);
1505 pcc_inode_get(pcci);
1506 WARN_ON(pccf->pccf_file);
1508 path = &pcci->pcci_path;
1509 CDEBUG(D_CACHE, "opening pcc file '%pd'\n", path->dentry);
1511 pcc_file = dentry_open(path, file->f_flags,
1512 pcc_super_cred(inode->i_sb));
1513 if (IS_ERR_OR_NULL(pcc_file)) {
1514 rc = pcc_file == NULL ? -EINVAL : PTR_ERR(pcc_file);
1515 pcc_inode_put(pcci);
1517 pccf->pccf_file = pcc_file;
1518 pccf->pccf_type = pcci->pcci_type;
1522 pcc_inode_unlock(inode);
1526 void pcc_file_release(struct inode *inode, struct file *file)
1528 struct pcc_inode *pcci;
1529 struct ll_file_data *fd = file->private_data;
1530 struct pcc_file *pccf;
1535 if (!S_ISREG(inode->i_mode) || fd == NULL)
1538 pccf = &fd->fd_pcc_file;
1539 pcc_inode_lock(inode);
1540 if (pccf->pccf_file == NULL)
1543 pcci = ll_i2pcci(inode);
1545 path = &pcci->pcci_path;
1546 CDEBUG(D_CACHE, "releasing pcc file \"%pd\"\n", path->dentry);
1547 pcc_inode_put(pcci);
1548 fput(pccf->pccf_file);
1549 pccf->pccf_file = NULL;
1551 pcc_inode_unlock(inode);
1555 static void pcc_io_init(struct inode *inode, enum pcc_io_type iot, bool *cached)
1557 struct pcc_inode *pcci;
1559 pcc_inode_lock(inode);
1560 pcci = ll_i2pcci(inode);
1561 if (pcci && pcc_inode_has_layout(pcci)) {
1562 LASSERT(atomic_read(&pcci->pcci_refcount) > 0);
1563 atomic_inc(&pcci->pcci_active_ios);
1567 if (pcc_may_auto_attach(inode, iot)) {
1568 (void) pcc_try_auto_attach(inode, cached, iot);
1570 pcci = ll_i2pcci(inode);
1571 LASSERT(atomic_read(&pcci->pcci_refcount) > 0);
1572 atomic_inc(&pcci->pcci_active_ios);
1576 pcc_inode_unlock(inode);
1579 static void pcc_io_fini(struct inode *inode)
1581 struct pcc_inode *pcci = ll_i2pcci(inode);
1583 LASSERT(pcci && atomic_read(&pcci->pcci_active_ios) > 0);
1584 if (atomic_dec_and_test(&pcci->pcci_active_ios))
1585 wake_up(&pcci->pcci_waitq);
1590 __pcc_file_read_iter(struct kiocb *iocb, struct iov_iter *iter)
1592 struct file *file = iocb->ki_filp;
1594 #ifdef HAVE_FILE_OPERATIONS_READ_WRITE_ITER
1595 return file->f_op->read_iter(iocb, iter);
1601 iov_for_each(iov, i, *iter) {
1604 res = file->f_op->aio_read(iocb, &iov, 1, iocb->ki_pos);
1605 if (-EIOCBQUEUED == res)
1606 res = wait_on_sync_kiocb(iocb);
1614 if (res < iov.iov_len)
1619 iov_iter_advance(iter, bytes);
1624 ssize_t pcc_file_read_iter(struct kiocb *iocb,
1625 struct iov_iter *iter, bool *cached)
1627 struct file *file = iocb->ki_filp;
1628 struct ll_file_data *fd = file->private_data;
1629 struct pcc_file *pccf = &fd->fd_pcc_file;
1630 struct inode *inode = file_inode(file);
1635 if (pccf->pccf_file == NULL) {
1640 pcc_io_init(inode, PIT_READ, cached);
1644 iocb->ki_filp = pccf->pccf_file;
1645 /* generic_file_aio_read does not support ext4-dax,
1646 * __pcc_file_read_iter uses ->aio_read hook directly
1647 * to add support for ext4-dax.
1649 result = __pcc_file_read_iter(iocb, iter);
1650 iocb->ki_filp = file;
1657 __pcc_file_write_iter(struct kiocb *iocb, struct iov_iter *iter)
1659 struct file *file = iocb->ki_filp;
1661 #ifdef HAVE_FILE_OPERATIONS_READ_WRITE_ITER
1662 return file->f_op->write_iter(iocb, iter);
1668 iov_for_each(iov, i, *iter) {
1671 res = file->f_op->aio_write(iocb, &iov, 1, iocb->ki_pos);
1672 if (-EIOCBQUEUED == res)
1673 res = wait_on_sync_kiocb(iocb);
1681 if (res < iov.iov_len)
1686 iov_iter_advance(iter, bytes);
1691 ssize_t pcc_file_write_iter(struct kiocb *iocb,
1692 struct iov_iter *iter, bool *cached)
1694 struct file *file = iocb->ki_filp;
1695 struct ll_file_data *fd = file->private_data;
1696 struct pcc_file *pccf = &fd->fd_pcc_file;
1697 struct inode *inode = file_inode(file);
1702 if (pccf->pccf_file == NULL) {
1707 if (pccf->pccf_type != LU_PCC_READWRITE) {
1712 pcc_io_init(inode, PIT_WRITE, cached);
1716 if (CFS_FAIL_CHECK(OBD_FAIL_LLITE_PCC_FAKE_ERROR))
1717 GOTO(out, result = -ENOSPC);
1719 iocb->ki_filp = pccf->pccf_file;
1721 /* Since __pcc_file_write_iter makes write calls via
1722 * the normal vfs interface to the local PCC file system,
1723 * the inode lock is not needed.
1725 result = __pcc_file_write_iter(iocb, iter);
1726 iocb->ki_filp = file;
1732 int pcc_inode_setattr(struct inode *inode, struct iattr *attr,
1736 const struct cred *old_cred;
1737 struct iattr attr2 = *attr;
1738 struct dentry *pcc_dentry;
1739 struct pcc_inode *pcci;
1743 if (!S_ISREG(inode->i_mode)) {
1748 pcc_io_init(inode, PIT_SETATTR, cached);
1752 attr2.ia_valid = attr->ia_valid & (ATTR_SIZE | ATTR_ATIME |
1753 ATTR_ATIME_SET | ATTR_MTIME | ATTR_MTIME_SET |
1754 ATTR_CTIME | ATTR_UID | ATTR_GID);
1755 pcci = ll_i2pcci(inode);
1756 pcc_dentry = pcci->pcci_path.dentry;
1757 inode_lock(pcc_dentry->d_inode);
1758 old_cred = override_creds(pcc_super_cred(inode->i_sb));
1759 #ifdef HAVE_USER_NAMESPACE_ARG
1760 rc = pcc_dentry->d_inode->i_op->setattr(&nop_mnt_idmap, pcc_dentry,
1763 rc = pcc_dentry->d_inode->i_op->setattr(pcc_dentry, &attr2);
1765 revert_creds(old_cred);
1766 inode_unlock(pcc_dentry->d_inode);
1772 int pcc_inode_getattr(struct inode *inode, u32 request_mask,
1773 unsigned int flags, bool *cached)
1775 struct ll_inode_info *lli = ll_i2info(inode);
1776 const struct cred *old_cred;
1785 if (!S_ISREG(inode->i_mode)) {
1790 pcc_io_init(inode, PIT_GETATTR, cached);
1794 old_cred = override_creds(pcc_super_cred(inode->i_sb));
1795 rc = ll_vfs_getattr(&ll_i2pcci(inode)->pcci_path, &stat, request_mask,
1797 revert_creds(old_cred);
1801 ll_inode_size_lock(inode);
1802 if (test_and_clear_bit(LLIF_UPDATE_ATIME, &lli->lli_flags) ||
1803 inode->i_atime.tv_sec < lli->lli_atime)
1804 inode->i_atime.tv_sec = lli->lli_atime;
1806 inode->i_mtime.tv_sec = lli->lli_mtime;
1807 inode->i_ctime.tv_sec = lli->lli_ctime;
1809 atime = inode->i_atime.tv_sec;
1810 mtime = inode->i_mtime.tv_sec;
1811 ctime = inode->i_ctime.tv_sec;
1813 if (atime < stat.atime.tv_sec)
1814 atime = stat.atime.tv_sec;
1816 if (ctime < stat.ctime.tv_sec)
1817 ctime = stat.ctime.tv_sec;
1819 if (mtime < stat.mtime.tv_sec)
1820 mtime = stat.mtime.tv_sec;
1822 i_size_write(inode, stat.size);
1823 inode->i_blocks = stat.blocks;
1825 inode->i_atime.tv_sec = atime;
1826 inode->i_mtime.tv_sec = mtime;
1827 inode->i_ctime.tv_sec = ctime;
1829 ll_inode_size_unlock(inode);
1835 #ifdef HAVE_DEFAULT_FILE_SPLICE_READ_EXPORT
1836 ssize_t pcc_file_splice_read(struct file *in_file, loff_t *ppos,
1837 struct pipe_inode_info *pipe,
1838 size_t count, unsigned int flags)
1840 struct inode *inode = file_inode(in_file);
1841 struct ll_file_data *fd = in_file->private_data;
1842 struct file *pcc_file = fd->fd_pcc_file.pccf_file;
1843 bool cached = false;
1849 RETURN(default_file_splice_read(in_file, ppos, pipe,
1852 pcc_io_init(inode, PIT_SPLICE_READ, &cached);
1854 RETURN(default_file_splice_read(in_file, ppos, pipe,
1857 result = default_file_splice_read(pcc_file, ppos, pipe, count, flags);
1862 #endif /* HAVE_DEFAULT_FILE_SPLICE_READ_EXPORT */
1864 int pcc_fsync(struct file *file, loff_t start, loff_t end,
1865 int datasync, bool *cached)
1867 struct inode *inode = file_inode(file);
1868 struct ll_file_data *fd = file->private_data;
1869 struct file *pcc_file = fd->fd_pcc_file.pccf_file;
1879 pcc_io_init(inode, PIT_FSYNC, cached);
1883 rc = file_inode(pcc_file)->i_fop->fsync(pcc_file,
1884 start, end, datasync);
1890 int pcc_file_mmap(struct file *file, struct vm_area_struct *vma,
1893 struct inode *inode = file_inode(file);
1894 struct ll_file_data *fd = file->private_data;
1895 struct file *pcc_file = fd->fd_pcc_file.pccf_file;
1896 struct pcc_inode *pcci;
1901 if (!pcc_file || !file_inode(pcc_file)->i_fop->mmap) {
1906 pcc_inode_lock(inode);
1907 pcci = ll_i2pcci(inode);
1908 if (pcci && pcc_inode_has_layout(pcci)) {
1909 LASSERT(atomic_read(&pcci->pcci_refcount) > 1);
1911 vma->vm_file = pcc_file;
1912 rc = file_inode(pcc_file)->i_fop->mmap(pcc_file, vma);
1913 vma->vm_file = file;
1914 /* Save the vm ops of backend PCC */
1915 vma->vm_private_data = (void *)vma->vm_ops;
1919 pcc_inode_unlock(inode);
1924 void pcc_vm_open(struct vm_area_struct *vma)
1926 struct pcc_inode *pcci;
1927 struct file *file = vma->vm_file;
1928 struct inode *inode = file_inode(file);
1929 struct ll_file_data *fd = file->private_data;
1930 struct file *pcc_file = fd->fd_pcc_file.pccf_file;
1931 struct vm_operations_struct *pcc_vm_ops = vma->vm_private_data;
1935 if (!pcc_file || !pcc_vm_ops || !pcc_vm_ops->open)
1938 pcc_inode_lock(inode);
1939 pcci = ll_i2pcci(inode);
1940 if (pcci && pcc_inode_has_layout(pcci)) {
1941 vma->vm_file = pcc_file;
1942 pcc_vm_ops->open(vma);
1943 vma->vm_file = file;
1945 pcc_inode_unlock(inode);
1949 void pcc_vm_close(struct vm_area_struct *vma)
1951 struct file *file = vma->vm_file;
1952 struct inode *inode = file_inode(file);
1953 struct ll_file_data *fd = file->private_data;
1954 struct file *pcc_file = fd->fd_pcc_file.pccf_file;
1955 struct vm_operations_struct *pcc_vm_ops = vma->vm_private_data;
1959 if (!pcc_file || !pcc_vm_ops || !pcc_vm_ops->close)
1962 pcc_inode_lock(inode);
1963 /* Layout lock maybe revoked here */
1964 vma->vm_file = pcc_file;
1965 pcc_vm_ops->close(vma);
1966 vma->vm_file = file;
1967 pcc_inode_unlock(inode);
1971 int pcc_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf,
1974 struct page *page = vmf->page;
1975 struct mm_struct *mm = vma->vm_mm;
1976 struct file *file = vma->vm_file;
1977 struct inode *inode = file_inode(file);
1978 struct ll_file_data *fd = file->private_data;
1979 struct file *pcc_file = fd->fd_pcc_file.pccf_file;
1980 struct vm_operations_struct *pcc_vm_ops = vma->vm_private_data;
1985 if (!pcc_file || !pcc_vm_ops) {
1990 if (!pcc_vm_ops->page_mkwrite &&
1991 page->mapping == pcc_file->f_mapping) {
1993 "%s: PCC backend fs not support ->page_mkwrite()\n",
1994 ll_i2sbi(inode)->ll_fsname);
1995 pcc_ioctl_detach(inode, PCC_DETACH_OPT_UNCACHE);
1996 mmap_read_unlock(mm);
1998 RETURN(VM_FAULT_RETRY | VM_FAULT_NOPAGE);
2000 /* Pause to allow for a race with concurrent detach */
2001 CFS_FAIL_TIMEOUT(OBD_FAIL_LLITE_PCC_MKWRITE_PAUSE, cfs_fail_val);
2003 pcc_io_init(inode, PIT_PAGE_MKWRITE, cached);
2005 /* This happens when the file is detached from PCC after got
2006 * the fault page via ->fault() on the inode of the PCC copy.
2007 * Here it can not simply fall back to normal Lustre I/O path.
2008 * The reason is that the address space of fault page used by
2009 * ->page_mkwrite() is still the one of PCC inode. In the
2010 * normal Lustre ->page_mkwrite() I/O path, it will be wrongly
2011 * handled as the address space of the fault page is not
2012 * consistent with the one of the Lustre inode (though the
2013 * fault page was truncated).
2014 * As the file is detached from PCC, the fault page must
2015 * be released frist, and retry the mmap write (->fault() and
2017 * We use an ugly and tricky method by returning
2018 * VM_FAULT_NOPAGE | VM_FAULT_RETRY to the caller
2019 * __do_page_fault and retry the memory fault handling.
2021 if (page->mapping == pcc_file->f_mapping) {
2023 mmap_read_unlock(mm);
2024 RETURN(VM_FAULT_RETRY | VM_FAULT_NOPAGE);
2031 * This fault injection can also be used to simulate -ENOSPC and
2032 * -EDQUOT failure of underlying PCC backend fs.
2034 if (CFS_FAIL_CHECK(OBD_FAIL_LLITE_PCC_DETACH_MKWRITE)) {
2036 pcc_ioctl_detach(inode, PCC_DETACH_OPT_UNCACHE);
2037 mmap_read_unlock(mm);
2038 RETURN(VM_FAULT_RETRY | VM_FAULT_NOPAGE);
2041 vma->vm_file = pcc_file;
2042 #ifdef HAVE_VM_OPS_USE_VM_FAULT_ONLY
2043 rc = pcc_vm_ops->page_mkwrite(vmf);
2045 rc = pcc_vm_ops->page_mkwrite(vma, vmf);
2047 vma->vm_file = file;
2053 int pcc_fault(struct vm_area_struct *vma, struct vm_fault *vmf,
2056 struct file *file = vma->vm_file;
2057 struct inode *inode = file_inode(file);
2058 struct ll_file_data *fd = file->private_data;
2059 struct file *pcc_file = fd->fd_pcc_file.pccf_file;
2060 struct vm_operations_struct *pcc_vm_ops = vma->vm_private_data;
2065 if (!pcc_file || !pcc_vm_ops || !pcc_vm_ops->fault) {
2070 pcc_io_init(inode, PIT_FAULT, cached);
2074 vma->vm_file = pcc_file;
2075 #ifdef HAVE_VM_OPS_USE_VM_FAULT_ONLY
2076 rc = pcc_vm_ops->fault(vmf);
2078 rc = pcc_vm_ops->fault(vma, vmf);
2080 vma->vm_file = file;
2086 static void __pcc_layout_invalidate(struct pcc_inode *pcci)
2088 pcci->pcci_type = LU_PCC_NONE;
2089 pcc_layout_gen_set(pcci, CL_LAYOUT_GEN_NONE);
2090 if (atomic_read(&pcci->pcci_active_ios) == 0)
2093 CDEBUG(D_CACHE, "Waiting for IO completion: %d\n",
2094 atomic_read(&pcci->pcci_active_ios));
2095 wait_event_idle(pcci->pcci_waitq,
2096 atomic_read(&pcci->pcci_active_ios) == 0);
2099 void pcc_layout_invalidate(struct inode *inode)
2101 struct pcc_inode *pcci;
2105 pcc_inode_lock(inode);
2106 pcci = ll_i2pcci(inode);
2107 if (pcci && pcc_inode_has_layout(pcci)) {
2108 LASSERT(atomic_read(&pcci->pcci_refcount) > 0);
2109 __pcc_layout_invalidate(pcci);
2111 CDEBUG(D_CACHE, "Invalidate "DFID" layout gen %d\n",
2112 PFID(&ll_i2info(inode)->lli_fid), pcci->pcci_layout_gen);
2114 pcc_inode_put(pcci);
2116 pcc_inode_unlock(inode);
2121 static int pcc_inode_remove(struct inode *inode, struct dentry *pcc_dentry)
2125 rc = vfs_unlink(&nop_mnt_idmap,
2126 pcc_dentry->d_parent->d_inode, pcc_dentry);
2128 CWARN("%s: failed to unlink PCC file %pd, rc = %d\n",
2129 ll_i2sbi(inode)->ll_fsname, pcc_dentry, rc);
2134 /* Create directory under base if directory does not exist */
2135 static struct dentry *
2136 pcc_mkdir(struct dentry *base, const char *name, umode_t mode)
2139 struct dentry *dentry;
2140 struct inode *dir = base->d_inode;
2143 dentry = lookup_one_len(name, base, strlen(name));
2147 if (d_is_positive(dentry))
2150 rc = vfs_mkdir(&nop_mnt_idmap, dir, dentry, mode);
2153 dentry = ERR_PTR(rc);
2161 static struct dentry *
2162 pcc_mkdir_p(struct dentry *root, char *path, umode_t mode)
2164 char *ptr, *entry_name;
2165 struct dentry *parent;
2166 struct dentry *child = ERR_PTR(-EINVAL);
2173 parent = dget(root);
2174 while ((ptr = strchr(ptr, '/')) != NULL) {
2176 child = pcc_mkdir(parent, entry_name, mode);
2190 /* Create file under base. If file already exist, return failure */
2191 static struct dentry *
2192 pcc_create(struct dentry *base, const char *name, umode_t mode)
2195 struct dentry *dentry;
2196 struct inode *dir = base->d_inode;
2199 dentry = lookup_one_len(name, base, strlen(name));
2203 if (d_is_positive(dentry))
2206 rc = vfs_create(&nop_mnt_idmap, dir, dentry, mode, false);
2209 dentry = ERR_PTR(rc);
2217 static int __pcc_inode_create(struct pcc_dataset *dataset,
2219 struct dentry **dentry)
2222 struct dentry *base;
2223 struct dentry *child;
2226 OBD_ALLOC(path, PCC_DATASET_MAX_PATH);
2230 pcc_fid2dataset_path(path, PCC_DATASET_MAX_PATH, fid);
2232 base = pcc_mkdir_p(dataset->pccd_path.dentry, path, 0);
2238 snprintf(path, PCC_DATASET_MAX_PATH, DFID_NOBRACE, PFID(fid));
2239 child = pcc_create(base, path, 0);
2240 if (IS_ERR(child)) {
2241 rc = PTR_ERR(child);
2249 OBD_FREE(path, PCC_DATASET_MAX_PATH);
2254 * Reset uid, gid or size for the PCC copy masked by @valid.
2255 * TODO: Set the project ID for PCC copy.
2257 static int pcc_inode_reset_iattr(struct dentry *dentry, unsigned int valid,
2258 kuid_t uid, kgid_t gid, loff_t size)
2260 struct inode *inode = dentry->d_inode;
2266 attr.ia_valid = valid;
2269 attr.ia_size = size;
2272 rc = notify_change(&nop_mnt_idmap, dentry, &attr, NULL);
2273 inode_unlock(inode);
2278 int pcc_inode_create(struct super_block *sb, struct pcc_dataset *dataset,
2279 struct lu_fid *fid, struct dentry **pcc_dentry)
2281 const struct cred *old_cred;
2284 old_cred = override_creds(pcc_super_cred(sb));
2285 rc = __pcc_inode_create(dataset, fid, pcc_dentry);
2286 revert_creds(old_cred);
2290 int pcc_inode_create_fini(struct inode *inode, struct pcc_create_attach *pca)
2292 struct dentry *pcc_dentry = pca->pca_dentry;
2293 struct pcc_super *super = ll_i2pccs(inode);
2294 const struct cred *old_cred;
2295 struct pcc_inode *pcci;
2300 if (!pca->pca_dataset)
2304 GOTO(out_dataset_put, rc = 0);
2306 LASSERT(pcc_dentry);
2308 old_cred = override_creds(super->pccs_cred);
2309 pcc_inode_lock(inode);
2310 LASSERT(ll_i2pcci(inode) == NULL);
2311 OBD_SLAB_ALLOC_PTR_GFP(pcci, pcc_inode_slab, GFP_NOFS);
2313 GOTO(out_put, rc = -ENOMEM);
2315 rc = pcc_inode_reset_iattr(pcc_dentry, ATTR_UID | ATTR_GID,
2316 old_cred->suid, old_cred->sgid, 0);
2320 pcc_inode_attach_set(super, pca->pca_dataset, ll_i2info(inode),
2321 pcci, pcc_dentry, LU_PCC_READWRITE);
2323 rc = pcc_layout_xattr_set(pcci, 0);
2325 (void) pcc_inode_remove(inode, pcci->pcci_path.dentry);
2326 pcc_inode_put(pcci);
2327 GOTO(out_unlock, rc);
2330 /* Set the layout generation of newly created file with 0 */
2331 pcc_layout_gen_set(pcci, 0);
2335 (void) pcc_inode_remove(inode, pcc_dentry);
2339 OBD_SLAB_FREE_PTR(pcci, pcc_inode_slab);
2342 pcc_inode_unlock(inode);
2343 revert_creds(old_cred);
2345 pcc_dataset_put(pca->pca_dataset);
2349 void pcc_create_attach_cleanup(struct super_block *sb,
2350 struct pcc_create_attach *pca)
2352 if (!pca->pca_dataset)
2355 if (pca->pca_dentry) {
2356 const struct cred *old_cred;
2359 old_cred = override_creds(pcc_super_cred(sb));
2360 rc = vfs_unlink(&nop_mnt_idmap,
2361 pca->pca_dentry->d_parent->d_inode,
2364 CWARN("%s: failed to unlink PCC file %pd: rc = %d\n",
2365 ll_s2sbi(sb)->ll_fsname, pca->pca_dentry, rc);
2366 /* ignore the unlink failure */
2367 revert_creds(old_cred);
2368 dput(pca->pca_dentry);
2371 pcc_dataset_put(pca->pca_dataset);
2374 static int pcc_filp_write(struct file *filp, const void *buf, ssize_t count,
2380 size = cfs_kernel_write(filp, buf, count, offset);
2389 static ssize_t pcc_copy_data(struct file *src, struct file *dst)
2393 loff_t pos, offset = 0;
2394 size_t buf_len = 1048576;
2399 OBD_ALLOC_LARGE(buf, buf_len);
2404 if (signal_pending(current))
2405 GOTO(out_free, rc = -EINTR);
2408 rc2 = cfs_kernel_read(src, buf, buf_len, &pos);
2410 GOTO(out_free, rc = rc2);
2415 rc = pcc_filp_write(dst, buf, rc2, &pos);
2423 OBD_FREE_LARGE(buf, buf_len);
2427 static int pcc_attach_allowed_check(struct inode *inode)
2429 struct ll_inode_info *lli = ll_i2info(inode);
2430 struct pcc_inode *pcci;
2435 pcc_inode_lock(inode);
2436 if (lli->lli_pcc_state & PCC_STATE_FL_ATTACHING)
2437 GOTO(out_unlock, rc = -EBUSY);
2439 pcci = ll_i2pcci(inode);
2440 if (pcci && pcc_inode_has_layout(pcci))
2441 GOTO(out_unlock, rc = -EEXIST);
2443 lli->lli_pcc_state |= PCC_STATE_FL_ATTACHING;
2445 pcc_inode_unlock(inode);
2449 int pcc_readwrite_attach(struct file *file, struct inode *inode,
2452 struct pcc_dataset *dataset;
2453 struct ll_inode_info *lli = ll_i2info(inode);
2454 struct pcc_super *super = ll_i2pccs(inode);
2455 struct pcc_inode *pcci;
2456 const struct cred *old_cred;
2457 struct dentry *dentry;
2458 struct file *pcc_filp;
2465 rc = pcc_attach_allowed_check(inode);
2469 dataset = pcc_dataset_get(&ll_i2sbi(inode)->ll_pcc_super,
2470 LU_PCC_READWRITE, archive_id);
2471 if (dataset == NULL)
2474 old_cred = override_creds(super->pccs_cred);
2475 rc = __pcc_inode_create(dataset, &lli->lli_fid, &dentry);
2477 GOTO(out_dataset_put, rc);
2479 path.mnt = dataset->pccd_path.mnt;
2480 path.dentry = dentry;
2481 pcc_filp = dentry_open(&path, O_WRONLY | O_LARGEFILE, current_cred());
2482 if (IS_ERR_OR_NULL(pcc_filp)) {
2483 rc = pcc_filp == NULL ? -EINVAL : PTR_ERR(pcc_filp);
2484 GOTO(out_dentry, rc);
2487 rc = pcc_inode_reset_iattr(dentry, ATTR_UID | ATTR_GID,
2488 old_cred->uid, old_cred->gid, 0);
2492 ret = pcc_copy_data(file, pcc_filp);
2494 GOTO(out_fput, rc = ret);
2497 * It must to truncate the PCC copy to the same size of the Lustre
2498 * copy after copy data. Otherwise, it may get wrong file size after
2499 * re-attach a file. See LU-13023 for details.
2501 rc = pcc_inode_reset_iattr(dentry, ATTR_SIZE, KUIDT_INIT(0),
2502 KGIDT_INIT(0), ret);
2506 /* Pause to allow for a race with concurrent HSM remove */
2507 CFS_FAIL_TIMEOUT(OBD_FAIL_LLITE_PCC_ATTACH_PAUSE, cfs_fail_val);
2509 pcc_inode_lock(inode);
2510 pcci = ll_i2pcci(inode);
2512 OBD_SLAB_ALLOC_PTR_GFP(pcci, pcc_inode_slab, GFP_NOFS);
2514 GOTO(out_unlock, rc = -ENOMEM);
2516 pcc_inode_attach_set(super, dataset, lli, pcci,
2517 dentry, LU_PCC_READWRITE);
2519 pcc_inode_unlock(inode);
2524 (void) pcc_inode_remove(inode, dentry);
2528 pcc_dataset_put(dataset);
2529 revert_creds(old_cred);
2534 int pcc_readwrite_attach_fini(struct file *file, struct inode *inode,
2535 __u32 gen, bool lease_broken, int rc,
2538 struct ll_inode_info *lli = ll_i2info(inode);
2539 const struct cred *old_cred;
2540 struct pcc_inode *pcci;
2545 old_cred = override_creds(pcc_super_cred(inode->i_sb));
2546 pcc_inode_lock(inode);
2547 pcci = ll_i2pcci(inode);
2548 if (rc || lease_broken) {
2549 if (attached && pcci)
2550 pcc_inode_put(pcci);
2552 GOTO(out_unlock, rc);
2555 /* PCC inode may be released due to layout lock revocatioin */
2557 GOTO(out_unlock, rc = -ESTALE);
2560 rc = pcc_layout_xattr_set(pcci, gen);
2564 LASSERT(lli->lli_pcc_state & PCC_STATE_FL_ATTACHING);
2565 rc = ll_layout_refresh(inode, &gen2);
2568 pcc_layout_gen_set(pcci, gen);
2571 DFID" layout changed from %d to %d.\n",
2572 PFID(ll_inode2fid(inode)), gen, gen2);
2573 GOTO(out_put, rc = -ESTALE);
2579 (void) pcc_inode_remove(inode, pcci->pcci_path.dentry);
2580 pcc_inode_put(pcci);
2583 lli->lli_pcc_state &= ~PCC_STATE_FL_ATTACHING;
2584 pcc_inode_unlock(inode);
2585 revert_creds(old_cred);
2589 static int pcc_hsm_remove(struct inode *inode)
2591 struct hsm_user_request *hur;
2598 rc = ll_layout_restore(inode, 0, OBD_OBJECT_EOF);
2600 CDEBUG(D_CACHE, DFID" RESTORE failure: %d\n",
2601 PFID(&ll_i2info(inode)->lli_fid), rc);
2605 ll_layout_refresh(inode, &gen);
2607 len = sizeof(struct hsm_user_request) +
2608 sizeof(struct hsm_user_item);
2609 OBD_ALLOC(hur, len);
2613 hur->hur_request.hr_action = HUA_REMOVE;
2614 hur->hur_request.hr_archive_id = 0;
2615 hur->hur_request.hr_flags = 0;
2616 memcpy(&hur->hur_user_item[0].hui_fid, &ll_i2info(inode)->lli_fid,
2617 sizeof(hur->hur_user_item[0].hui_fid));
2618 hur->hur_user_item[0].hui_extent.offset = 0;
2619 hur->hur_user_item[0].hui_extent.length = OBD_OBJECT_EOF;
2620 hur->hur_request.hr_itemcount = 1;
2621 rc = obd_iocontrol(LL_IOC_HSM_REQUEST, ll_i2sbi(inode)->ll_md_exp,
2624 CDEBUG(D_CACHE, DFID" HSM REMOVE failure: %d\n",
2625 PFID(&ll_i2info(inode)->lli_fid), rc);
2631 int pcc_ioctl_detach(struct inode *inode, __u32 opt)
2633 struct ll_inode_info *lli = ll_i2info(inode);
2634 struct pcc_inode *pcci;
2635 bool hsm_remove = false;
2640 pcc_inode_lock(inode);
2641 pcci = lli->lli_pcc_inode;
2642 if (!pcci || lli->lli_pcc_state & PCC_STATE_FL_ATTACHING ||
2643 !pcc_inode_has_layout(pcci))
2644 GOTO(out_unlock, rc = 0);
2646 LASSERT(atomic_read(&pcci->pcci_refcount) > 0);
2648 if (pcci->pcci_type == LU_PCC_READWRITE) {
2649 if (opt == PCC_DETACH_OPT_UNCACHE) {
2652 * The file will be removed from PCC, set the flags
2653 * with PCC_DATASET_NONE even the later removal of the
2656 lli->lli_pcc_dsflags = PCC_DATASET_NONE;
2659 __pcc_layout_invalidate(pcci);
2660 pcc_inode_put(pcci);
2664 pcc_inode_unlock(inode);
2666 const struct cred *old_cred;
2668 old_cred = override_creds(pcc_super_cred(inode->i_sb));
2669 rc = pcc_hsm_remove(inode);
2670 revert_creds(old_cred);
2676 int pcc_ioctl_state(struct file *file, struct inode *inode,
2677 struct lu_pcc_state *state)
2683 int buf_len = sizeof(state->pccs_path);
2684 struct ll_file_data *fd = file->private_data;
2685 struct pcc_file *pccf = &fd->fd_pcc_file;
2686 struct pcc_inode *pcci;
2693 OBD_ALLOC(buf, buf_len);
2697 pcc_inode_lock(inode);
2698 pcci = ll_i2pcci(inode);
2700 state->pccs_type = LU_PCC_NONE;
2701 GOTO(out_unlock, rc = 0);
2704 count = atomic_read(&pcci->pcci_refcount);
2706 state->pccs_type = LU_PCC_NONE;
2707 state->pccs_open_count = 0;
2708 GOTO(out_unlock, rc = 0);
2711 if (pcc_inode_has_layout(pcci))
2713 if (pccf->pccf_file != NULL)
2715 state->pccs_type = pcci->pcci_type;
2716 state->pccs_open_count = count;
2717 state->pccs_flags = ll_i2info(inode)->lli_pcc_state;
2718 path = dentry_path_raw(pcci->pcci_path.dentry, buf, buf_len);
2720 GOTO(out_unlock, rc = PTR_ERR(path));
2722 if (strlcpy(state->pccs_path, path, buf_len) >= buf_len)
2723 GOTO(out_unlock, rc = -ENAMETOOLONG);
2726 pcc_inode_unlock(inode);
2727 OBD_FREE(buf, buf_len);