1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
4 * Lustre Light Super operations
6 * Copyright (c) 2002, 2003 Cluster File Systems, Inc.
8 * This file is part of Lustre, http://www.lustre.org.
10 * Lustre is free software; you can redistribute it and/or
11 * modify it under the terms of version 2 of the GNU General Public
12 * License as published by the Free Software Foundation.
14 * Lustre is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with Lustre; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #define DEBUG_SUBSYSTEM S_LLITE
26 #include <linux/module.h>
27 #include <linux/random.h>
28 #include <linux/version.h>
30 #include <linux/lustre_lite.h>
31 #include <linux/lustre_ha.h>
32 #include <linux/lustre_dlm.h>
33 #include <linux/lprocfs_status.h>
34 #include "llite_internal.h"
36 kmem_cache_t *ll_file_data_slab;
38 extern struct address_space_operations ll_aops;
39 extern struct address_space_operations ll_dir_aops;
40 extern struct super_operations ll_super_operations;
43 #define log2(n) ffz(~(n))
46 struct ll_sb_info *lustre_init_sbi(struct super_block *sb)
48 struct ll_sb_info *sbi = NULL;
52 OBD_ALLOC(sbi, sizeof(*sbi));
56 INIT_LIST_HEAD(&sbi->ll_conn_chain);
57 INIT_HLIST_HEAD(&sbi->ll_orphan_dentry_list);
60 generate_random_uuid(uuid);
61 class_uuid_unparse(uuid, &sbi->ll_sb_uuid);
65 void lustre_free_sbi(struct super_block *sb)
67 struct ll_sb_info *sbi = ll_s2sbi(sb);
71 OBD_FREE(sbi, sizeof(*sbi));
76 int lustre_common_fill_super(struct super_block *sb, char *mdc, char *osc)
78 struct inode *root = 0;
79 struct ll_sb_info *sbi = ll_s2sbi(sb);
80 struct obd_device *obd;
81 struct ll_fid rootfid;
82 struct obd_statfs osfs;
83 struct ptlrpc_request *request = NULL;
84 struct lustre_handle osc_conn = {0, };
85 struct lustre_handle mdc_conn = {0, };
90 obd = class_name2obd(mdc);
92 CERROR("MDC %s: not setup or attached\n", mdc);
96 if (proc_lustre_fs_root) {
97 err = lprocfs_register_mountpoint(proc_lustre_fs_root, sb,
100 CERROR("could not register mount in /proc/lustre");
103 mdc_init_ea_size(obd, osc);
105 err = obd_connect(&mdc_conn, obd, &sbi->ll_sb_uuid);
107 CERROR("An MDS (mdc %s) is performing recovery, of which this"
108 " client is not a part. Please wait for recovery to "
109 "complete, abort, or time out.\n", mdc);
112 CERROR("cannot connect to %s: rc = %d\n", mdc, err);
115 sbi->ll_mdc_exp = class_conn2export(&mdc_conn);
117 err = obd_statfs(obd, &osfs, jiffies - HZ);
121 LASSERT(osfs.os_bsize);
122 sb->s_blocksize = osfs.os_bsize;
123 sb->s_blocksize_bits = log2(osfs.os_bsize);
124 sb->s_magic = LL_SUPER_MAGIC;
125 sb->s_maxbytes = PAGE_CACHE_MAXBYTES;
127 devno = get_uuid2int(sbi2mdc(sbi)->cl_import->imp_target_uuid.uuid,
128 strlen(sbi2mdc(sbi)->cl_import->imp_target_uuid.uuid));
131 obd = class_name2obd(osc);
133 CERROR("OSC %s: not setup or attached\n", osc);
137 err = obd_connect(&osc_conn, obd, &sbi->ll_sb_uuid);
139 CERROR("An OST (osc %s) is performing recovery, of which this"
140 " client is not a part. Please wait for recovery to "
141 "complete, abort, or time out.\n", osc);
144 CERROR("cannot connect to %s: rc = %d\n", osc, err);
147 sbi->ll_osc_exp = class_conn2export(&osc_conn);
149 err = mdc_getstatus(sbi->ll_mdc_exp, &rootfid);
151 CERROR("cannot mds_connect: rc = %d\n", err);
154 CDEBUG(D_SUPER, "rootfid "LPU64"\n", rootfid.id);
155 sbi->ll_rootino = rootfid.id;
157 sb->s_op = &lustre_super_operations;
160 * XXX: move this to after cbd setup? */
161 err = mdc_getattr(sbi->ll_mdc_exp, &rootfid,
162 OBD_MD_FLNOTOBD|OBD_MD_FLBLOCKS, 0, &request);
164 CERROR("mdc_getattr failed for root: rc = %d\n", err);
168 err = mdc_req2lustre_md(request, 0, sbi->ll_osc_exp, &md);
170 CERROR("failed to understand root inode md: rc = %d\n",err);
171 ptlrpc_req_finished (request);
175 LASSERT(sbi->ll_rootino != 0);
176 root = ll_iget(sb, sbi->ll_rootino, &md);
178 ptlrpc_req_finished(request);
180 if (root == NULL || is_bad_inode(root)) {
181 /* XXX might need iput() for bad inode */
182 CERROR("lustre_lite: bad iget4 for root\n");
183 GOTO(out_root, err = -EBADF);
186 err = ll_close_thread_start(&sbi->ll_lcq);
188 CERROR("cannot start close thread: rc %d\n", err);
192 sb->s_root = d_alloc_root(root);
199 obd_disconnect(sbi->ll_osc_exp, 0);
201 obd_disconnect(sbi->ll_mdc_exp, 0);
203 lprocfs_unregister_mountpoint(sbi);
207 void lustre_common_put_super(struct super_block *sb)
209 struct ll_sb_info *sbi = ll_s2sbi(sb);
210 struct hlist_node *tmp, *next;
213 ll_close_thread_shutdown(sbi->ll_lcq);
215 list_del(&sbi->ll_conn_chain);
216 obd_disconnect(sbi->ll_osc_exp, 0);
218 lprocfs_unregister_mountpoint(sbi);
219 if (sbi->ll_proc_root) {
220 lprocfs_remove(sbi->ll_proc_root);
221 sbi->ll_proc_root = NULL;
224 obd_disconnect(sbi->ll_mdc_exp, 0);
226 // We do this to get rid of orphaned dentries. That is not really trw.
227 spin_lock(&dcache_lock);
228 hlist_for_each_safe(tmp, next, &sbi->ll_orphan_dentry_list) {
229 struct dentry *dentry = hlist_entry(tmp, struct dentry, d_hash);
230 shrink_dcache_parent(dentry);
232 spin_unlock(&dcache_lock);
237 char *ll_read_opt(const char *opt, char *data)
243 CDEBUG(D_SUPER, "option: %s, data %s\n", opt, data);
244 if (strncmp(opt, data, strlen(opt)))
246 if ((value = strchr(data, '=')) == NULL)
250 OBD_ALLOC(retval, strlen(value) + 1);
252 CERROR("out of memory!\n");
256 memcpy(retval, value, strlen(value)+1);
257 CDEBUG(D_SUPER, "Assigned option: %s, value %s\n", opt, retval);
261 int ll_set_opt(const char *opt, char *data, int fl)
265 CDEBUG(D_SUPER, "option: %s, data %s\n", opt, data);
266 if (strncmp(opt, data, strlen(opt)))
272 void ll_options(char *options, char **ost, char **mdc, int *flags)
275 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,0))
276 char *opt_ptr = options;
285 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
286 for (this_char = strtok (options, ",");
288 this_char = strtok (NULL, ",")) {
290 while ((this_char = strsep (&opt_ptr, ",")) != NULL) {
292 CDEBUG(D_SUPER, "this_char %s\n", this_char);
293 if (!*ost && (*ost = ll_read_opt("osc", this_char)))
295 if (!*mdc && (*mdc = ll_read_opt("mdc", this_char)))
297 if (!(*flags & LL_SBI_NOLCK) &&
298 ((*flags) = (*flags) |
299 ll_set_opt("nolock", this_char,
306 void ll_lli_init(struct ll_inode_info *lli)
308 sema_init(&lli->lli_open_sem, 1);
310 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
311 spin_lock_init(&lli->lli_lock);
312 INIT_LIST_HEAD(&lli->lli_pending_write_llaps);
315 int ll_fill_super(struct super_block *sb, void *data, int silent)
317 struct ll_sb_info *sbi;
323 CDEBUG(D_VFSTRACE, "VFS Op: sb %p\n", sb);
325 sbi = lustre_init_sbi(sb);
329 sbi->ll_flags |= LL_SBI_READAHEAD;
330 ll_options(data, &osc, &mdc, &sbi->ll_flags);
334 GOTO(out, err = -EINVAL);
339 GOTO(out, err = -EINVAL);
342 err = lustre_common_fill_super(sb, mdc, osc);
348 OBD_FREE(mdc, strlen(mdc) + 1);
350 OBD_FREE(osc, strlen(osc) + 1);
353 } /* ll_read_super */
355 void ll_put_super(struct super_block *sb)
359 CDEBUG(D_VFSTRACE, "VFS Op: sb %p\n", sb);
361 lustre_common_put_super(sb);
368 int lustre_process_log(struct lustre_mount_data *lmd, char * profile,
369 struct config_llog_instance *cfg)
371 struct lustre_cfg lcfg;
372 struct portals_cfg pcfg;
373 char * peer = "MDS_PEER_UUID";
374 struct obd_device *obd;
375 struct lustre_handle mdc_conn = {0, };
376 struct obd_export *exp;
377 char * name = "mdc_dev";
379 struct obd_uuid mdc_uuid;
380 struct llog_ctxt *ctxt;
385 generate_random_uuid(uuid);
386 class_uuid_unparse(uuid, &mdc_uuid);
388 if (lmd->lmd_local_nid) {
389 PCFG_INIT(pcfg, NAL_CMD_REGISTER_MYNID);
390 pcfg.pcfg_nal = lmd->lmd_nal;
391 pcfg.pcfg_nid = lmd->lmd_local_nid;
392 err = kportal_nal_cmd(&pcfg);
397 if (lmd->lmd_nal == SOCKNAL) {
398 PCFG_INIT(pcfg, NAL_CMD_ADD_AUTOCONN);
399 pcfg.pcfg_nal = lmd->lmd_nal;
400 pcfg.pcfg_nid = lmd->lmd_server_nid;
401 pcfg.pcfg_id = lmd->lmd_server_ipaddr;
402 pcfg.pcfg_misc = lmd->lmd_port;
404 pcfg.pcfg_flags = 0x4; /*share*/
405 err = kportal_nal_cmd(&pcfg);
410 LCFG_INIT(lcfg, LCFG_ADD_UUID, name);
411 lcfg.lcfg_nid = lmd->lmd_server_nid;
412 lcfg.lcfg_inllen1 = strlen(peer) + 1;
413 lcfg.lcfg_inlbuf1 = peer;
414 lcfg.lcfg_nal = lmd->lmd_nal;
415 err = class_process_config(&lcfg);
417 GOTO(out_del_conn, err);
419 LCFG_INIT(lcfg, LCFG_ATTACH, name);
420 lcfg.lcfg_inlbuf1 = "mdc";
421 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
422 lcfg.lcfg_inlbuf2 = mdc_uuid.uuid;
423 lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1;
424 err = class_process_config(&lcfg);
426 GOTO(out_del_uuid, err);
428 LCFG_INIT(lcfg, LCFG_SETUP, name);
429 lcfg.lcfg_inlbuf1 = lmd->lmd_mds;
430 lcfg.lcfg_inllen1 = strlen(lcfg.lcfg_inlbuf1) + 1;
431 lcfg.lcfg_inlbuf2 = peer;
432 lcfg.lcfg_inllen2 = strlen(lcfg.lcfg_inlbuf2) + 1;
433 err = class_process_config(&lcfg);
435 GOTO(out_detach, err);
437 obd = class_name2obd(name);
439 GOTO(out_cleanup, err = -EINVAL);
441 err = obd_connect(&mdc_conn, obd, &mdc_uuid);
443 CERROR("cannot connect to %s: rc = %d\n", lmd->lmd_mds, err);
444 GOTO(out_cleanup, err);
447 exp = class_conn2export(&mdc_conn);
449 ctxt = llog_get_context(exp->exp_obd, LLOG_CONFIG_REPL_CTXT);
450 rc = class_config_parse_llog(ctxt, profile, cfg);
452 CERROR("class_config_parse_llog failed: rc = %d\n", rc);
455 err = obd_disconnect(exp, 0);
458 LCFG_INIT(lcfg, LCFG_CLEANUP, name);
459 err = class_process_config(&lcfg);
464 LCFG_INIT(lcfg, LCFG_DETACH, name);
465 err = class_process_config(&lcfg);
470 LCFG_INIT(lcfg, LCFG_DEL_UUID, name);
471 lcfg.lcfg_inllen1 = strlen(peer) + 1;
472 lcfg.lcfg_inlbuf1 = peer;
473 err = class_process_config(&lcfg);
476 if (lmd->lmd_nal == SOCKNAL) {
477 PCFG_INIT(pcfg, NAL_CMD_DEL_AUTOCONN);
478 pcfg.pcfg_nal = lmd->lmd_nal;
479 pcfg.pcfg_nid = lmd->lmd_server_nid;
480 pcfg.pcfg_id = lmd->lmd_server_ipaddr;
481 pcfg.pcfg_flags = 1; /*share*/
482 err = kportal_nal_cmd(&pcfg);
493 int lustre_fill_super(struct super_block *sb, void *data, int silent)
495 struct lustre_mount_data * lmd = data;
496 struct ll_sb_info *sbi;
502 CDEBUG(D_VFSTRACE, "VFS Op: sb %p\n", sb);
503 sbi = lustre_init_sbi(sb);
507 sbi->ll_flags |= LL_SBI_READAHEAD;
509 if (lmd->lmd_profile) {
510 struct lustre_profile *lprof;
511 struct config_llog_instance cfg;
515 CERROR("no mds name\n");
516 GOTO(out_free, err = -EINVAL);
519 OBD_ALLOC(sbi->ll_lmd, sizeof(*sbi->ll_lmd));
520 if (sbi->ll_lmd == NULL)
521 GOTO(out_free, err = -ENOMEM);
522 memcpy(sbi->ll_lmd, lmd, sizeof(*lmd));
524 /* generate a string unique to this super, let's try
525 the address of the super itself.*/
526 len = (sizeof(sb) * 2) + 1;
527 OBD_ALLOC(sbi->ll_instance, len);
528 if (sbi->ll_instance == NULL)
529 GOTO(out_free, err = -ENOMEM);
530 sprintf(sbi->ll_instance, "%p", sb);
532 cfg.cfg_instance = sbi->ll_instance;
533 cfg.cfg_uuid = sbi->ll_sb_uuid;
534 cfg.cfg_local_nid = lmd->lmd_local_nid;
535 err = lustre_process_log(lmd, lmd->lmd_profile, &cfg);
537 CERROR("Unable to process log: %s\n", lmd->lmd_profile);
542 lprof = class_get_profile(lmd->lmd_profile);
544 CERROR("No profile found: %s\n", lmd->lmd_profile);
545 GOTO(out_free, err = -EINVAL);
548 OBD_FREE(osc, strlen(osc) + 1);
549 OBD_ALLOC(osc, strlen(lprof->lp_osc) +
550 strlen(sbi->ll_instance) + 2);
551 sprintf(osc, "%s-%s", lprof->lp_osc, sbi->ll_instance);
554 OBD_FREE(mdc, strlen(mdc) + 1);
555 OBD_ALLOC(mdc, strlen(lprof->lp_mdc) +
556 strlen(sbi->ll_instance) + 2);
557 sprintf(mdc, "%s-%s", lprof->lp_mdc, sbi->ll_instance);
562 GOTO(out_free, err = -EINVAL);
567 GOTO(out_free, err = -EINVAL);
570 err = lustre_common_fill_super(sb, mdc, osc);
577 OBD_FREE(mdc, strlen(mdc) + 1);
579 OBD_FREE(osc, strlen(osc) + 1);
585 int len = strlen(sbi->ll_lmd->lmd_profile) + sizeof("-clean")+1;
588 if (sbi->ll_instance != NULL) {
590 struct config_llog_instance cfg;
592 cfg.cfg_instance = sbi->ll_instance;
593 cfg.cfg_uuid = sbi->ll_sb_uuid;
595 OBD_ALLOC(cln_prof, len);
596 sprintf(cln_prof, "%s-clean", sbi->ll_lmd->lmd_profile);
598 err = lustre_process_log(sbi->ll_lmd, cln_prof, &cfg);
600 CERROR("Unable to process log: %s\n", cln_prof);
601 OBD_FREE(cln_prof, len);
602 OBD_FREE(sbi->ll_instance, strlen(sbi->ll_instance)+ 1);
604 OBD_FREE(sbi->ll_lmd, sizeof(*sbi->ll_lmd));
609 } /* lustre_fill_super */
611 void lustre_put_super(struct super_block *sb)
613 struct ll_sb_info *sbi = ll_s2sbi(sb);
616 CDEBUG(D_VFSTRACE, "VFS Op: sb %p\n", sb);
618 lustre_common_put_super(sb);
620 if (sbi->ll_lmd != NULL) {
622 int len = strlen(sbi->ll_lmd->lmd_profile) + sizeof("-clean")+1;
624 struct config_llog_instance cfg;
626 cfg.cfg_instance = sbi->ll_instance;
627 cfg.cfg_uuid = sbi->ll_sb_uuid;
629 OBD_ALLOC(cln_prof, len);
630 sprintf(cln_prof, "%s-clean", sbi->ll_lmd->lmd_profile);
632 err = lustre_process_log(sbi->ll_lmd, cln_prof, &cfg);
634 CERROR("Unable to process log: %s\n", cln_prof);
636 OBD_FREE(cln_prof, len);
637 OBD_FREE(sbi->ll_lmd, sizeof(*sbi->ll_lmd));
638 OBD_FREE(sbi->ll_instance, strlen(sbi->ll_instance) + 1);
644 } /* lustre_put_super */
647 struct inode *ll_inode_from_lock(struct ldlm_lock *lock)
650 l_lock(&lock->l_resource->lr_namespace->ns_lock);
651 if (lock->l_ast_data)
652 inode = igrab(lock->l_ast_data);
655 l_unlock(&lock->l_resource->lr_namespace->ns_lock);
659 static int null_if_equal(struct ldlm_lock *lock, void *data)
661 if (data == lock->l_ast_data)
662 lock->l_ast_data = NULL;
664 if (lock->l_req_mode != lock->l_granted_mode)
665 return LDLM_ITER_STOP;
667 return LDLM_ITER_CONTINUE;
670 void ll_clear_inode(struct inode *inode)
673 struct ll_inode_info *lli = ll_i2info(inode);
674 struct ll_sb_info *sbi = ll_i2sbi(inode);
677 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
678 inode->i_generation, inode);
680 ll_inode2fid(&fid, inode);
681 clear_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &(ll_i2info(inode)->lli_flags));
682 mdc_change_cbdata(sbi->ll_mdc_exp, &fid, null_if_equal, inode);
685 obd_change_cbdata(sbi->ll_osc_exp, lli->lli_smd,
686 null_if_equal, inode);
689 obd_free_memmd(sbi->ll_osc_exp, &lli->lli_smd);
693 if (lli->lli_symlink_name) {
694 OBD_FREE(lli->lli_symlink_name,
695 strlen(lli->lli_symlink_name) + 1);
696 lli->lli_symlink_name = NULL;
702 /* If this inode has objects allocated to it (lsm != NULL), then the OST
703 * object(s) determine the file size and mtime. Otherwise, the MDS will
704 * keep these values until such a time that objects are allocated for it.
705 * We do the MDS operations first, as it is checking permissions for us.
706 * We don't to the MDS RPC if there is nothing that we want to store there,
707 * otherwise there is no harm in updating mtime/atime on the MDS if we are
708 * going to do an RPC anyways.
710 * If we are doing a truncate, we will send the mtime and ctime updates
711 * to the OST with the punch RPC, otherwise we do an explicit setattr RPC.
712 * I don't believe it is possible to get e.g. ATTR_MTIME_SET and ATTR_SIZE
715 int ll_setattr_raw(struct inode *inode, struct iattr *attr)
717 struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
718 struct ll_sb_info *sbi = ll_i2sbi(inode);
719 struct ptlrpc_request *request = NULL;
720 struct mdc_op_data op_data;
721 int ia_valid = attr->ia_valid;
725 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu\n", inode->i_ino);
726 lprocfs_counter_incr(ll_i2sbi(inode)->ll_stats, LPROC_LL_SETATTR);
728 if (ia_valid & ATTR_SIZE) {
729 if (attr->ia_size > ll_file_maxbytes(inode)) {
730 CDEBUG(D_INODE, "file too large %llu > "LPU64"\n",
731 attr->ia_size, ll_file_maxbytes(inode));
735 attr->ia_valid |= ATTR_MTIME | ATTR_CTIME;
738 /* POSIX: check before ATTR_*TIME_SET set (from inode_change_ok) */
739 if (ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET)) {
740 if (current->fsuid != inode->i_uid && !capable(CAP_FOWNER))
744 /* We mark all of the fields "set" so MDS/OST does not re-set them */
745 if (attr->ia_valid & ATTR_CTIME) {
746 attr->ia_ctime = CURRENT_TIME;
747 attr->ia_valid |= ATTR_CTIME_SET;
749 if (!(ia_valid & ATTR_ATIME_SET) && (attr->ia_valid & ATTR_ATIME)) {
750 attr->ia_atime = CURRENT_TIME;
751 attr->ia_valid |= ATTR_ATIME_SET;
753 if (!(ia_valid & ATTR_MTIME_SET) && (attr->ia_valid & ATTR_MTIME)) {
754 attr->ia_mtime = CURRENT_TIME;
755 attr->ia_valid |= ATTR_MTIME_SET;
758 if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
759 CDEBUG(D_INODE, "setting mtime %lu, ctime %lu, now = %lu\n",
760 LTIME_S(attr->ia_mtime), LTIME_S(attr->ia_ctime),
761 LTIME_S(CURRENT_TIME));
763 attr->ia_valid &= ~ATTR_SIZE;
765 /* If only OST attributes being set on objects, don't do MDS RPC.
766 * In that case, we need to check permissions and update the local
767 * inode ourselves so we can call obdo_from_inode() always. */
768 if (ia_valid & (lsm ? ~(ATTR_SIZE | ATTR_FROM_OPEN | ATTR_RAW) : ~0)) {
770 ll_prepare_mdc_op_data(&op_data, inode, NULL, NULL, 0, 0);
772 rc = mdc_setattr(sbi->ll_mdc_exp, &op_data,
773 attr, NULL, 0, NULL, 0, &request);
776 ptlrpc_req_finished(request);
777 if (rc != -EPERM && rc != -EACCES)
778 CERROR("mdc_setattr fails: rc = %d\n", rc);
782 rc = mdc_req2lustre_md(request, 0, sbi->ll_osc_exp, &md);
784 ptlrpc_req_finished(request);
788 /* Won't invoke vmtruncate as we already cleared ATTR_SIZE,
789 * but needed to set timestamps backwards on utime. */
790 inode_setattr(inode, attr);
791 ll_update_inode(inode, md.body, md.lsm);
792 ptlrpc_req_finished(request);
794 if (!lsm || !S_ISREG(inode->i_mode)) {
795 CDEBUG(D_INODE, "no lsm: not setting attrs on OST\n");
799 /* The OST doesn't check permissions, but the alternative is
800 * a gratuitous RPC to the MDS. We already rely on the client
801 * to do read/write/truncate permission checks, so is mtime OK?
803 if (ia_valid & (ATTR_MTIME | ATTR_ATIME)) {
804 /* from sys_utime() */
805 if (!(ia_valid & (ATTR_MTIME_SET | ATTR_ATIME_SET))) {
806 if (current->fsuid != inode->i_uid &&
807 (rc = ll_permission(inode, MAY_WRITE, NULL)) != 0)
810 /* from inode_change_ok() */
811 if (current->fsuid != inode->i_uid &&
812 !capable(CAP_FOWNER))
817 /* Won't invoke vmtruncate, as we already cleared ATTR_SIZE */
818 inode_setattr(inode, attr);
821 /* We really need to get our PW lock before we change inode->i_size.
822 * If we don't we can race with other i_size updaters on our node, like
823 * ll_file_read. We can also race with i_size propogation to other
824 * nodes through dirtying and writeback of final cached pages. This
825 * last one is especially bad for racing o_append users on other
827 if (ia_valid & ATTR_SIZE) {
828 struct ldlm_extent extent = { .start = attr->ia_size,
829 .end = OBD_OBJECT_EOF };
830 struct lustre_handle lockh = { 0 };
831 int err, ast_flags = 0;
832 /* XXX when we fix the AST intents to pass the discard-range
833 * XXX extent, make ast_flags always LDLM_AST_DISCARD_DATA
835 if (attr->ia_size == 0)
836 ast_flags = LDLM_AST_DISCARD_DATA;
838 /* bug 1639: avoid write/truncate i_sem/DLM deadlock */
839 LASSERT(atomic_read(&inode->i_sem.count) <= 0);
841 rc = ll_extent_lock_no_validate(NULL, inode, lsm, LCK_PW,
842 &extent, &lockh, ast_flags);
847 rc = vmtruncate(inode, attr->ia_size);
849 set_bit(LLI_F_HAVE_OST_SIZE_LOCK,
850 &ll_i2info(inode)->lli_flags);
852 //ll_try_done_writing(inode);
854 /* unlock now as we don't mind others file lockers racing with
855 * the mds updates below? */
856 err = ll_extent_unlock(NULL, inode, lsm, LCK_PW, &lockh);
858 CERROR("ll_extent_unlock failed: %d\n", err);
862 } else if (ia_valid & (ATTR_MTIME | ATTR_MTIME_SET)) {
865 CDEBUG(D_INODE, "set mtime on OST inode %lu to %lu\n",
866 inode->i_ino, LTIME_S(attr->ia_mtime));
867 oa.o_id = lsm->lsm_object_id;
868 oa.o_valid = OBD_MD_FLID;
869 obdo_from_inode(&oa, inode, OBD_MD_FLTYPE | OBD_MD_FLATIME |
870 OBD_MD_FLMTIME | OBD_MD_FLCTIME);
871 rc = obd_setattr(sbi->ll_osc_exp, &oa, lsm, NULL);
873 CERROR("obd_setattr fails: rc=%d\n", rc);
878 int ll_setattr(struct dentry *de, struct iattr *attr)
880 LBUG(); /* code is unused, but leave this in case of VFS changes */
884 int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
885 unsigned long max_age)
887 struct ll_sb_info *sbi = ll_s2sbi(sb);
888 struct obd_statfs obd_osfs;
892 rc = obd_statfs(class_exp2obd(sbi->ll_mdc_exp), osfs, max_age);
894 CERROR("mdc_statfs fails: rc = %d\n", rc);
898 CDEBUG(D_SUPER, "MDC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
899 osfs->os_bavail, osfs->os_blocks, osfs->os_ffree,osfs->os_files);
901 rc = obd_statfs(class_exp2obd(sbi->ll_osc_exp), &obd_osfs, max_age);
903 CERROR("obd_statfs fails: rc = %d\n", rc);
907 CDEBUG(D_SUPER, "OSC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
908 obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
911 osfs->os_blocks = obd_osfs.os_blocks;
912 osfs->os_bfree = obd_osfs.os_bfree;
913 osfs->os_bavail = obd_osfs.os_bavail;
915 /* If we don't have as many objects free on the OST as inodes
916 * on the MDS, we reduce the total number of inodes to
917 * compensate, so that the "inodes in use" number is correct.
919 if (obd_osfs.os_ffree < osfs->os_ffree) {
920 osfs->os_files = (osfs->os_files - osfs->os_ffree) +
922 osfs->os_ffree = obd_osfs.os_ffree;
928 int ll_statfs(struct super_block *sb, struct kstatfs *sfs)
930 struct obd_statfs osfs;
933 CDEBUG(D_VFSTRACE, "VFS Op:\n");
934 lprocfs_counter_incr(ll_s2sbi(sb)->ll_stats, LPROC_LL_STAFS);
936 /* For now we will always get up-to-date statfs values, but in the
937 * future we may allow some amount of caching on the client (e.g.
938 * from QOS or lprocfs updates). */
939 rc = ll_statfs_internal(sb, &osfs, jiffies - 1);
943 statfs_unpack(sfs, &osfs);
945 if (sizeof(sfs->f_blocks) == 4) {
946 while (osfs.os_blocks > ~0UL) {
949 osfs.os_blocks >>= 1;
951 osfs.os_bavail >>= 1;
955 sfs->f_blocks = osfs.os_blocks;
956 sfs->f_bfree = osfs.os_bfree;
957 sfs->f_bavail = osfs.os_bavail;
962 void dump_lsm(int level, struct lov_stripe_md *lsm)
964 CDEBUG(level, "objid "LPX64", maxbytes "LPX64", magic 0x%08X, "
965 "stripe_size %u, stripe_count %u\n",
966 lsm->lsm_object_id, lsm->lsm_maxbytes, lsm->lsm_magic,
967 lsm->lsm_stripe_size, lsm->lsm_stripe_count);
970 void ll_update_inode(struct inode *inode, struct mds_body *body,
971 struct lov_stripe_md *lsm)
973 struct ll_inode_info *lli = ll_i2info(inode);
975 LASSERT ((lsm != NULL) == ((body->valid & OBD_MD_FLEASIZE) != 0));
977 if (lli->lli_smd == NULL) {
979 lli->lli_maxbytes = lsm->lsm_maxbytes;
980 if (lli->lli_maxbytes > PAGE_CACHE_MAXBYTES)
981 lli->lli_maxbytes = PAGE_CACHE_MAXBYTES;
983 if (memcmp(lli->lli_smd, lsm, sizeof(*lsm))) {
984 CERROR("lsm mismatch for inode %ld\n",
986 CERROR("lli_smd:\n");
987 dump_lsm(D_ERROR, lli->lli_smd);
989 dump_lsm(D_ERROR, lsm);
993 if (lli->lli_smd != lsm)
994 obd_free_memmd(ll_i2obdexp(inode), &lsm);
997 if (body->valid & OBD_MD_FLID)
998 inode->i_ino = body->ino;
999 if (body->valid & OBD_MD_FLATIME)
1000 LTIME_S(inode->i_atime) = body->atime;
1001 if (body->valid & OBD_MD_FLMTIME &&
1002 body->mtime > LTIME_S(inode->i_mtime)) {
1003 CDEBUG(D_INODE, "setting ino %lu mtime from %lu to %u\n",
1004 inode->i_ino, LTIME_S(inode->i_mtime), body->mtime);
1005 LTIME_S(inode->i_mtime) = body->mtime;
1007 if (body->valid & OBD_MD_FLCTIME &&
1008 body->ctime > LTIME_S(inode->i_ctime))
1009 LTIME_S(inode->i_ctime) = body->ctime;
1010 if (body->valid & OBD_MD_FLMODE)
1011 inode->i_mode = (inode->i_mode & S_IFMT)|(body->mode & ~S_IFMT);
1012 if (body->valid & OBD_MD_FLTYPE)
1013 inode->i_mode = (inode->i_mode & ~S_IFMT)|(body->mode & S_IFMT);
1014 if (body->valid & OBD_MD_FLUID)
1015 inode->i_uid = body->uid;
1016 if (body->valid & OBD_MD_FLGID)
1017 inode->i_gid = body->gid;
1018 if (body->valid & OBD_MD_FLFLAGS)
1019 inode->i_flags = body->flags;
1020 if (body->valid & OBD_MD_FLNLINK)
1021 inode->i_nlink = body->nlink;
1022 if (body->valid & OBD_MD_FLGENER)
1023 inode->i_generation = body->generation;
1024 if (body->valid & OBD_MD_FLRDEV)
1025 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
1026 inode->i_rdev = body->rdev;
1028 inode->i_rdev = old_encode_dev(body->rdev);
1030 if (body->valid & OBD_MD_FLSIZE)
1031 inode->i_size = body->size;
1032 if (body->valid & OBD_MD_FLBLOCKS)
1033 inode->i_blocks = body->blocks;
1035 if (body->valid & OBD_MD_FLSIZE)
1036 set_bit(LLI_F_HAVE_MDS_SIZE_LOCK, &lli->lli_flags);
1039 void ll_read_inode2(struct inode *inode, void *opaque)
1041 struct lustre_md *md = opaque;
1042 struct ll_inode_info *lli = ll_i2info(inode);
1045 CDEBUG(D_VFSTRACE, "VFS Op:inode=%lu/%u(%p)\n", inode->i_ino,
1046 inode->i_generation, inode);
1050 LASSERT(!lli->lli_smd);
1052 /* Core attributes from the MDS first. This is a new inode, and
1053 * the VFS doesn't zero times in the core inode so we have to do
1054 * it ourselves. They will be overwritten by either MDS or OST
1055 * attributes - we just need to make sure they aren't newer. */
1056 LTIME_S(inode->i_mtime) = 0;
1057 LTIME_S(inode->i_atime) = 0;
1058 LTIME_S(inode->i_ctime) = 0;
1059 ll_update_inode(inode, md->body, md->lsm);
1061 /* OIDEBUG(inode); */
1063 if (S_ISREG(inode->i_mode)) {
1064 inode->i_op = &ll_file_inode_operations;
1065 inode->i_fop = &ll_file_operations;
1066 inode->i_mapping->a_ops = &ll_aops;
1068 } else if (S_ISDIR(inode->i_mode)) {
1069 inode->i_op = &ll_dir_inode_operations;
1070 inode->i_fop = &ll_dir_operations;
1071 inode->i_mapping->a_ops = &ll_dir_aops;
1073 } else if (S_ISLNK(inode->i_mode)) {
1074 inode->i_op = &ll_fast_symlink_inode_operations;
1077 inode->i_op = &ll_special_inode_operations;
1078 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0))
1079 init_special_inode(inode, inode->i_mode,
1080 kdev_t_to_nr(inode->i_rdev));
1082 init_special_inode(inode, inode->i_mode, inode->i_rdev);
1088 int ll_iocontrol(struct inode *inode, struct file *file,
1089 unsigned int cmd, unsigned long arg)
1091 struct ll_sb_info *sbi = ll_i2sbi(inode);
1092 struct ptlrpc_request *req = NULL;
1097 case EXT3_IOC_GETFLAGS: {
1099 unsigned long valid = OBD_MD_FLFLAGS;
1100 struct mds_body *body;
1102 ll_inode2fid(&fid, inode);
1103 rc = mdc_getattr(sbi->ll_mdc_exp, &fid, valid, 0, &req);
1105 CERROR("failure %d inode %lu\n", rc, inode->i_ino);
1109 body = lustre_msg_buf(req->rq_repmsg, 0, sizeof(*body));
1111 if (body->flags & S_APPEND)
1112 flags |= EXT3_APPEND_FL;
1113 if (body->flags & S_IMMUTABLE)
1114 flags |= EXT3_IMMUTABLE_FL;
1115 if (body->flags & S_NOATIME)
1116 flags |= EXT3_NOATIME_FL;
1118 ptlrpc_req_finished (req);
1120 RETURN(put_user(flags, (int *)arg));
1122 case EXT3_IOC_SETFLAGS: {
1123 struct mdc_op_data op_data;
1126 struct lov_stripe_md *lsm = ll_i2info(inode)->lli_smd;
1128 if (get_user(flags, (int *)arg))
1135 ll_prepare_mdc_op_data(&op_data, inode, NULL, NULL, 0, 0);
1137 memset(&attr, 0x0, sizeof(attr));
1138 attr.ia_attr_flags = flags;
1139 attr.ia_valid |= ATTR_ATTR_FLAG;
1141 rc = mdc_setattr(sbi->ll_mdc_exp, &op_data,
1142 &attr, NULL, 0, NULL, 0, &req);
1144 ptlrpc_req_finished(req);
1145 if (rc != -EPERM && rc != -EACCES)
1146 CERROR("mdc_setattr fails: rc = %d\n", rc);
1150 ptlrpc_req_finished(req);
1152 oa->o_id = lsm->lsm_object_id;
1153 oa->o_flags = flags;
1154 oa->o_valid = OBD_MD_FLID | OBD_MD_FLFLAGS;
1156 rc = obd_setattr(sbi->ll_osc_exp, oa, lsm, NULL);
1159 if (rc != -EPERM && rc != -EACCES)
1160 CERROR("mdc_setattr fails: rc = %d\n", rc);
1164 if (flags & EXT3_APPEND_FL)
1165 inode->i_flags |= S_APPEND;
1167 inode->i_flags &= ~S_APPEND;
1168 if (flags & EXT3_IMMUTABLE_FL)
1169 inode->i_flags |= S_IMMUTABLE;
1171 inode->i_flags &= ~S_IMMUTABLE;
1172 if (flags & EXT3_NOATIME_FL)
1173 inode->i_flags |= S_NOATIME;
1175 inode->i_flags &= ~S_NOATIME;
1186 void ll_umount_begin(struct super_block *sb)
1188 struct ll_sb_info *sbi = ll_s2sbi(sb);
1189 struct obd_device *obd;
1190 struct obd_ioctl_data ioc_data = { 0 };
1192 CDEBUG(D_VFSTRACE, "VFS Op:\n");
1194 obd = class_exp2obd(sbi->ll_mdc_exp);
1196 CERROR("Invalid MDC connection handle "LPX64"\n",
1197 sbi->ll_mdc_exp->exp_handle.h_cookie);
1201 obd->obd_no_recov = 1;
1202 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_mdc_exp, sizeof ioc_data,
1205 obd = class_exp2obd(sbi->ll_osc_exp);
1207 CERROR("Invalid LOV connection handle "LPX64"\n",
1208 sbi->ll_osc_exp->exp_handle.h_cookie);
1213 obd->obd_no_recov = 1;
1214 obd_iocontrol(IOC_OSC_SET_ACTIVE, sbi->ll_osc_exp, sizeof ioc_data,
1217 /* Really, we'd like to wait until there are no requests outstanding,
1218 * and then continue. For now, we just invalidate the requests,
1219 * schedule, and hope.
1226 int ll_prep_inode(struct obd_export *exp, struct inode **inode,
1227 struct ptlrpc_request *req, int offset,struct super_block *sb)
1229 struct lustre_md md;
1232 rc = mdc_req2lustre_md(req, offset, exp, &md);
1237 ll_update_inode(*inode, md.body, md.lsm);
1240 *inode = ll_iget(sb, md.body->ino, &md);
1241 if (*inode == NULL || is_bad_inode(*inode)) {
1242 /* free the lsm if we allocated one above */
1244 obd_free_memmd(exp, &md.lsm);
1246 CERROR("new_inode -fatal: rc %d\n", rc);