Whamcloud - gitweb
LU-4423 llite: use 64-bit times in another debug print
[fs/lustre-release.git] / lustre / llite / llite_lib.c
index d442e22..4d80ff5 100644 (file)
  *
  * You should have received a copy of the GNU General Public License
  * version 2 along with this program; If not, see
- * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
+ * http://www.gnu.org/licenses/gpl-2.0.html
  *
  * GPL HEADER END
  */
@@ -27,7 +23,7 @@
  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2015, Intel Corporation.
+ * Copyright (c) 2011, 2016, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -50,6 +46,7 @@
 #ifdef HAVE_UIDGID_HEADER
 # include <linux/uidgid.h>
 #endif
+#include <linux/security.h>
 
 #include <lustre_ioctl.h>
 #include <lustre_ha.h>
@@ -117,6 +114,7 @@ static struct ll_sb_info *ll_init_sbi(void)
 #ifdef HAVE_LRU_RESIZE_SUPPORT
         sbi->ll_flags |= LL_SBI_LRU_RESIZE;
 #endif
+       sbi->ll_flags |= LL_SBI_LAZYSTATFS;
 
         for (i = 0; i <= LL_PROCESS_HIST_MAX; i++) {
                spin_lock_init(&sbi->ll_rw_extents_info.pp_extents[i].
@@ -160,6 +158,12 @@ static void ll_free_sbi(struct super_block *sb)
        EXIT;
 }
 
+static inline int obd_connect_has_secctx(struct obd_connect_data *data)
+{
+       return data->ocd_connect_flags & OBD_CONNECT_FLAGS2 &&
+              data->ocd_connect_flags2 & OBD_CONNECT2_FILE_SECCTX;
+}
+
 static int client_common_fill_super(struct super_block *sb, char *md, char *dt,
                                     struct vfsmount *mnt)
 {
@@ -211,7 +215,7 @@ static int client_common_fill_super(struct super_block *sb, char *md, char *dt,
                                  OBD_CONNECT_DIR_STRIPE |
                                  OBD_CONNECT_BULK_MBITS |
                                  OBD_CONNECT_SUBTREE |
-                                 OBD_CONNECT_FLAGS2;
+                                 OBD_CONNECT_FLAGS2 | OBD_CONNECT_MULTIMODRPCS;
 
        data->ocd_connect_flags2 = 0;
 
@@ -243,13 +247,14 @@ static int client_common_fill_super(struct super_block *sb, char *md, char *dt,
         else
                 sbi->ll_fop = &ll_file_operations_noflock;
 
-        /* real client */
-        data->ocd_connect_flags |= OBD_CONNECT_REAL;
-
        /* always ping even if server suppress_pings */
        if (sbi->ll_flags & LL_SBI_ALWAYS_PING)
                data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
 
+#ifdef HAVE_SECURITY_DENTRY_INIT_SECURITY
+       data->ocd_connect_flags2 |= OBD_CONNECT2_FILE_SECCTX;
+#endif /* HAVE_SECURITY_DENTRY_INIT_SECURITY */
+
        data->ocd_brw_size = MD_MAX_BRW_SIZE;
 
         err = obd_connect(NULL, &sbi->ll_md_exp, obd, &sbi->ll_sb_uuid, data, NULL);
@@ -295,15 +300,15 @@ static int client_common_fill_super(struct super_block *sb, char *md, char *dt,
            valid != CLIENT_CONNECT_MDT_REQD) {
                char *buf;
 
-               OBD_ALLOC_WAIT(buf, PAGE_CACHE_SIZE);
-               obd_connect_flags2str(buf, PAGE_CACHE_SIZE,
+               OBD_ALLOC_WAIT(buf, PAGE_SIZE);
+               obd_connect_flags2str(buf, PAGE_SIZE,
                                      valid ^ CLIENT_CONNECT_MDT_REQD, 0, ",");
                LCONSOLE_ERROR_MSG(0x170, "Server %s does not support "
                                   "feature(s) needed for correct operation "
                                   "of this client (%s). Please upgrade "
                                   "server or downgrade client.\n",
                                   sbi->ll_md_exp->exp_obd->obd_name, buf);
-               OBD_FREE(buf, PAGE_CACHE_SIZE);
+               OBD_FREE(buf, PAGE_SIZE);
                GOTO(out_md_fid, err = -EPROTO);
        }
 
@@ -317,11 +322,12 @@ static int client_common_fill_super(struct super_block *sb, char *md, char *dt,
        }
 
        LASSERT(osfs->os_bsize);
-        sb->s_blocksize = osfs->os_bsize;
-        sb->s_blocksize_bits = log2(osfs->os_bsize);
-        sb->s_magic = LL_SUPER_MAGIC;
-        sb->s_maxbytes = MAX_LFS_FILESIZE;
-        sbi->ll_namelen = osfs->os_namelen;
+       sb->s_blocksize = osfs->os_bsize;
+       sb->s_blocksize_bits = log2(osfs->os_bsize);
+       sb->s_magic = LL_SUPER_MAGIC;
+       sb->s_maxbytes = MAX_LFS_FILESIZE;
+       sbi->ll_namelen = osfs->os_namelen;
+       sbi->ll_mnt.mnt = current->fs->root.mnt;
 
         if ((sbi->ll_flags & LL_SBI_USER_XATTR) &&
             !(data->ocd_connect_flags & OBD_CONNECT_XATTR)) {
@@ -347,13 +353,16 @@ static int client_common_fill_super(struct super_block *sb, char *md, char *dt,
                 sbi->ll_flags |= LL_SBI_64BIT_HASH;
 
        if (data->ocd_connect_flags & OBD_CONNECT_BRW_SIZE)
-               sbi->ll_md_brw_pages = data->ocd_brw_size >> PAGE_CACHE_SHIFT;
+               sbi->ll_md_brw_pages = data->ocd_brw_size >> PAGE_SHIFT;
        else
                sbi->ll_md_brw_pages = 1;
 
        if (data->ocd_connect_flags & OBD_CONNECT_LAYOUTLOCK)
                sbi->ll_flags |= LL_SBI_LAYOUT_LOCK;
 
+       if (obd_connect_has_secctx(data))
+               sbi->ll_flags |= LL_SBI_FILE_SECCTX;
+
        if (data->ocd_ibits_known & MDS_INODELOCK_XATTR) {
                if (!(data->ocd_connect_flags & OBD_CONNECT_MAX_EASIZE)) {
                        LCONSOLE_INFO("%s: disabling xattr cache due to "
@@ -412,7 +421,7 @@ static int client_common_fill_super(struct super_block *sb, char *md, char *dt,
        if (sbi->ll_flags & LL_SBI_ALWAYS_PING)
                data->ocd_connect_flags &= ~OBD_CONNECT_PINGLESS;
 
-       CDEBUG(D_RPCTRACE, "ocd_connect_flags: "LPX64" ocd_version: %d "
+       CDEBUG(D_RPCTRACE, "ocd_connect_flags: %#llx ocd_version: %d "
               "ocd_grant: %d\n", data->ocd_connect_flags,
               data->ocd_version, data->ocd_grant);
 
@@ -526,11 +535,21 @@ static int client_common_fill_super(struct super_block *sb, char *md, char *dt,
        err = obd_set_info_async(NULL, sbi->ll_dt_exp, sizeof(KEY_CHECKSUM),
                                 KEY_CHECKSUM, sizeof(checksum), &checksum,
                                 NULL);
+       if (err) {
+               CERROR("%s: Set checksum failed: rc = %d\n",
+                      sbi->ll_dt_exp->exp_obd->obd_name, err);
+               GOTO(out_root, err);
+       }
        cl_sb_init(sb);
 
        err = obd_set_info_async(NULL, sbi->ll_dt_exp, sizeof(KEY_CACHE_SET),
                                 KEY_CACHE_SET, sizeof(*sbi->ll_cache),
                                 sbi->ll_cache, NULL);
+       if (err) {
+               CERROR("%s: Set cache_set failed: rc = %d\n",
+                      sbi->ll_dt_exp->exp_obd->obd_name, err);
+               GOTO(out_root, err);
+       }
 
        sb->s_root = d_make_root(root);
        if (sb->s_root == NULL) {
@@ -900,7 +919,6 @@ void ll_lli_init(struct ll_inode_info *lli)
        lli->lli_posix_acl = NULL;
        /* Do not set lli_fid, it has been initialized already. */
        fid_zero(&lli->lli_pfid);
-       atomic_set(&lli->lli_open_count, 0);
        lli->lli_mds_read_och = NULL;
         lli->lli_mds_write_och = NULL;
         lli->lli_mds_exec_och = NULL;
@@ -937,6 +955,7 @@ void ll_lli_init(struct ll_inode_info *lli)
                lli->lli_async_rc = 0;
        }
        mutex_init(&lli->lli_layout_mutex);
+       memset(lli->lli_jobid, 0, LUSTRE_JOBID_SIZE);
 }
 
 static inline int ll_bdi_register(struct backing_dev_info *bdi)
@@ -1006,6 +1025,7 @@ int ll_fill_super(struct super_block *sb, struct vfsmount *mnt)
         cfg->cfg_instance = sb;
         cfg->cfg_uuid = lsi->lsi_llsbi->ll_sb_uuid;
        cfg->cfg_callback = class_config_llog_handler;
+       cfg->cfg_sub_clds = CONFIG_SUB_CLIENT;
         /* set up client obds */
         err = lustre_process_log(sb, profilenm, cfg);
        if (err < 0)
@@ -1495,10 +1515,10 @@ static int ll_md_setattr(struct dentry *dentry, struct md_op_data *op_data)
         * cache is not cleared yet. */
        op_data->op_attr.ia_valid &= ~(TIMES_SET_FLAGS | ATTR_SIZE);
        if (S_ISREG(inode->i_mode))
-               mutex_lock(&inode->i_mutex);
+               inode_lock(inode);
        rc = simple_setattr(dentry, &op_data->op_attr);
        if (S_ISREG(inode->i_mode))
-               mutex_unlock(&inode->i_mutex);
+               inode_unlock(inode);
        op_data->op_attr.ia_valid = ia_valid;
 
        rc = ll_update_inode(inode, &md);
@@ -1546,7 +1566,7 @@ int ll_setattr_raw(struct dentry *dentry, struct iattr *attr, bool hsm_import)
                  * OST maximum object size and number of stripes.  This
                  * needs another check in addition to the VFS check above. */
                 if (attr->ia_size > ll_file_maxbytes(inode)) {
-                        CDEBUG(D_INODE,"file "DFID" too large %llu > "LPU64"\n",
+                       CDEBUG(D_INODE,"file "DFID" too large %llu > %llu\n",
                                PFID(&lli->lli_fid), attr->ia_size,
                                ll_file_maxbytes(inode));
                         RETURN(-EFBIG);
@@ -1580,14 +1600,14 @@ int ll_setattr_raw(struct dentry *dentry, struct iattr *attr, bool hsm_import)
         }
 
         if (attr->ia_valid & (ATTR_MTIME | ATTR_CTIME))
-                CDEBUG(D_INODE, "setting mtime %lu, ctime %lu, now = %lu\n",
+               CDEBUG(D_INODE, "setting mtime %lu, ctime %lu, now = %llu\n",
                        LTIME_S(attr->ia_mtime), LTIME_S(attr->ia_ctime),
-                       cfs_time_current_sec());
+                      (s64)ktime_get_real_seconds());
 
        if (S_ISREG(inode->i_mode)) {
                if (attr->ia_valid & ATTR_SIZE)
                        inode_dio_write_done(inode);
-               mutex_unlock(&inode->i_mutex);
+               inode_unlock(inode);
        }
 
        /* We always do an MDS RPC, even if we're only changing the size;
@@ -1664,7 +1684,7 @@ out:
                ll_finish_md_op_data(op_data);
 
        if (S_ISREG(inode->i_mode)) {
-               mutex_lock(&inode->i_mutex);
+               inode_lock(inode);
                if ((attr->ia_valid & ATTR_SIZE) && !hsm_import)
                        inode_dio_wait(inode);
        }
@@ -1721,7 +1741,7 @@ int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
 
         osfs->os_type = sb->s_magic;
 
-        CDEBUG(D_SUPER, "MDC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
+       CDEBUG(D_SUPER, "MDC blocks %llu/%llu objects %llu/%llu\n",
                osfs->os_bavail, osfs->os_blocks, osfs->os_ffree,osfs->os_files);
 
         if (sbi->ll_flags & LL_SBI_LAZYSTATFS)
@@ -1733,7 +1753,7 @@ int ll_statfs_internal(struct super_block *sb, struct obd_statfs *osfs,
                 RETURN(rc);
         }
 
-        CDEBUG(D_SUPER, "OSC blocks "LPU64"/"LPU64" objects "LPU64"/"LPU64"\n",
+       CDEBUG(D_SUPER, "OSC blocks %llu/%llu objects %llu/%llu\n",
                obd_osfs.os_bavail, obd_osfs.os_blocks, obd_osfs.os_ffree,
                obd_osfs.os_files);
 
@@ -1761,7 +1781,7 @@ int ll_statfs(struct dentry *de, struct kstatfs *sfs)
        __u64 fsid = huge_encode_dev(sb->s_dev);
        int rc;
 
-        CDEBUG(D_VFSTRACE, "VFS Op: at "LPU64" jiffies\n", get_jiffies_64());
+       CDEBUG(D_VFSTRACE, "VFS Op: at %llu jiffies\n", get_jiffies_64());
         ll_stats_ops_tally(ll_s2sbi(sb), LPROC_LL_STAFS, 1);
 
         /* Some amount of caching on the client is allowed */
@@ -1852,7 +1872,7 @@ int ll_update_inode(struct inode *inode, struct lustre_md *md)
        if (body->mbo_valid & OBD_MD_FLMTIME) {
                if (body->mbo_mtime > LTIME_S(inode->i_mtime)) {
                        CDEBUG(D_INODE, "setting ino %lu mtime from %lu "
-                              "to "LPU64"\n", inode->i_ino,
+                              "to %llu\n", inode->i_ino,
                               LTIME_S(inode->i_mtime), body->mbo_mtime);
                        LTIME_S(inode->i_mtime) = body->mbo_mtime;
                }
@@ -2111,6 +2131,8 @@ void ll_umount_begin(struct super_block *sb)
        struct ll_sb_info *sbi = ll_s2sbi(sb);
        struct obd_device *obd;
        struct obd_ioctl_data *ioc_data;
+       struct l_wait_info lwi;
+       wait_queue_head_t waitq;
        ENTRY;
 
        CDEBUG(D_VFSTRACE, "VFS Op: superblock %p count %d active %d\n", sb,
@@ -2118,7 +2140,7 @@ void ll_umount_begin(struct super_block *sb)
 
        obd = class_exp2obd(sbi->ll_md_exp);
        if (obd == NULL) {
-               CERROR("Invalid MDC connection handle "LPX64"\n",
+               CERROR("Invalid MDC connection handle %#llx\n",
                       sbi->ll_md_exp->exp_handle.h_cookie);
                EXIT;
                return;
@@ -2127,7 +2149,7 @@ void ll_umount_begin(struct super_block *sb)
 
         obd = class_exp2obd(sbi->ll_dt_exp);
         if (obd == NULL) {
-                CERROR("Invalid LOV connection handle "LPX64"\n",
+               CERROR("Invalid LOV connection handle %#llx\n",
                        sbi->ll_dt_exp->exp_handle.h_cookie);
                 EXIT;
                 return;
@@ -2146,10 +2168,14 @@ void ll_umount_begin(struct super_block *sb)
        }
 
        /* Really, we'd like to wait until there are no requests outstanding,
-        * and then continue.  For now, we just invalidate the requests,
-        * schedule() and sleep one second if needed, and hope.
+        * and then continue.  For now, we just periodically checking for vfs
+        * to decrement mnt_cnt and hope to finish it within 10sec.
         */
-       schedule();
+       init_waitqueue_head(&waitq);
+       lwi = LWI_TIMEOUT_INTERVAL(cfs_time_seconds(10),
+                                  cfs_time_seconds(1), NULL, NULL);
+       l_wait_event(waitq, may_umount(sbi->ll_mnt.mnt), &lwi);
+
        EXIT;
 }
 
@@ -2220,7 +2246,7 @@ void ll_open_cleanup(struct super_block *sb, struct ptlrpc_request *open_req)
 
        op_data->op_fid1 = body->mbo_fid1;
        op_data->op_handle = body->mbo_handle;
-       op_data->op_mod_time = cfs_time_current_sec();
+       op_data->op_mod_time = ktime_get_real_seconds();
        md_close(exp, op_data, NULL, &close_req);
        ptlrpc_req_finished(close_req);
        ll_finish_md_op_data(op_data);
@@ -2458,6 +2484,8 @@ struct md_op_data *ll_prep_md_op_data(struct md_op_data *op_data,
 
 void ll_finish_md_op_data(struct md_op_data *op_data)
 {
+       security_release_secctx(op_data->op_file_secctx,
+                               op_data->op_file_secctx_size);
         OBD_FREE_PTR(op_data);
 }
 
@@ -2637,7 +2665,7 @@ void ll_compute_rootsquash_state(struct ll_sb_info *sbi)
        struct root_squash_info *squash = &sbi->ll_squash;
        int i;
        bool matched;
-       lnet_process_id_t id;
+       struct lnet_process_id id;
 
        /* Update norootsquash flag */
        down_write(&squash->rsi_sem);
@@ -2682,7 +2710,7 @@ static int ll_linkea_decode(struct linkea_data *ldata, unsigned int linkno,
        int             rc;
        ENTRY;
 
-       rc = linkea_init(ldata);
+       rc = linkea_init_with_rec(ldata);
        if (rc < 0)
                RETURN(rc);