Whamcloud - gitweb
LU-11304 misc: update all url links to whamcloud
[fs/lustre-release.git] / lustre / ofd / ofd_obd.c
index cd9f673..aa59c14 100644 (file)
@@ -23,7 +23,7 @@
  * Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2012, 2016, Intel Corporation.
+ * Copyright (c) 2012, 2017, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
 
 #define DEBUG_SUBSYSTEM S_FILTER
 
-#include <lustre/lustre_idl.h>
 #include "ofd_internal.h"
 #include <obd_cksum.h>
-#include <lustre_ioctl.h>
+#include <uapi/linux/lustre/lustre_ioctl.h>
 #include <lustre_quota.h>
 #include <lustre_lfsck.h>
 #include <lustre_nodemap.h>
@@ -73,8 +72,6 @@ static int ofd_export_stats_init(struct ofd_device *ofd,
        int                      rc;
        ENTRY;
 
-       LASSERT(obd->obd_uses_nid_stats);
-
        if (obd_uuid_equals(&exp->exp_client_uuid, &obd->obd_uuid))
                /* Self-export gets no proc entry */
                RETURN(0);
@@ -85,14 +82,11 @@ static int ofd_export_stats_init(struct ofd_device *ofd,
                RETURN(rc == -EALREADY ? 0 : rc);
 
        stats = exp->exp_nid_stats;
-       stats->nid_stats = lprocfs_alloc_stats(NUM_OBD_STATS +
-                                               LPROC_OFD_STATS_LAST,
-                                               LPROCFS_STATS_FLAG_NOPERCPU);
+       stats->nid_stats = lprocfs_alloc_stats(LPROC_OFD_STATS_LAST,
+                                              LPROCFS_STATS_FLAG_NOPERCPU);
        if (stats->nid_stats == NULL)
                RETURN(-ENOMEM);
 
-       lprocfs_init_ops_stats(LPROC_OFD_STATS_LAST, stats->nid_stats);
-
        ofd_stats_counter_init(stats->nid_stats);
 
        rc = lprocfs_register_stats(stats->nid_proc, "stats", stats->nid_stats);
@@ -110,6 +104,93 @@ out:
 }
 
 /**
+ * Decide which checksums both client and OST support, possibly forcing
+ * the use of T10PI checksums if the hardware supports this.
+ *
+ * The clients that have no T10-PI RPC checksum support will use the same
+ * mechanism to select checksum type as before, and will not be affected by
+ * the following logic.
+ *
+ * For the clients that have T10-PI RPC checksum support:
+ *
+ * If the OST supports T10-PI feature and T10-PI checksum is enforced, clients
+ * will have no other choice for RPC checksum type other than using the T10PI
+ * checksum type. This is useful for enforcing end-to-end integrity in the
+ * whole system.
+ *
+ * If the OST doesn't support T10-PI feature and T10-PI checksum is enforced,
+ * together with other checksum with reasonably good speeds (e.g. crc32,
+ * crc32c, adler, etc.), all T10-PI checksum types understood by the client
+ * (t10ip512, t10ip4K, t10crc512, t10crc4K) will be added to the available
+ * checksum types, regardless of the speeds of T10-PI checksums. This is
+ * useful for testing T10-PI checksum of RPC.
+ *
+ * If the OST supports T10-PI feature and T10-PI checksum is NOT enforced,
+ * the corresponding T10-PI checksum type will be added to the checksum type
+ * list, regardless of the speed of the T10-PI checksum. This provides clients
+ * the flexibility to choose whether to enable end-to-end integrity or not.
+ *
+ * If the OST does NOT supports T10-PI feature and T10-PI checksum is NOT
+ * enforced, together with other checksums with reasonably good speeds,
+ * all the T10-PI checksum types with good speeds will be added into the
+ * checksum type list. Note that a T10-PI checksum type with a speed worse
+ * than half of Alder will NOT be added as a option. In this circumstance,
+ * T10-PI checksum types has the same behavior like other normal checksum
+ * types.
+ *
+ */
+static void
+ofd_mask_cksum_types(struct ofd_device *ofd, enum cksum_types *cksum_types)
+{
+       bool enforce = ofd->ofd_checksum_t10pi_enforce;
+       enum cksum_types ofd_t10_cksum_type;
+       enum cksum_types client_t10_types = *cksum_types & OBD_CKSUM_T10_ALL;
+       enum cksum_types server_t10_types;
+
+       /*
+        * The client set in ocd_cksum_types the checksum types it
+        * supports. We have to mask off the algorithms that we don't
+        * support. T10PI checksum types will be added later.
+        */
+       *cksum_types &= (ofd->ofd_cksum_types_supported & ~OBD_CKSUM_T10_ALL);
+       server_t10_types = ofd->ofd_cksum_types_supported & OBD_CKSUM_T10_ALL;
+       ofd_t10_cksum_type = ofd->ofd_lut.lut_dt_conf.ddp_t10_cksum_type;
+
+       /* Quick exit if no T10-PI support on client */
+       if (!client_t10_types)
+               return;
+
+       /*
+        * This OST has NO T10-PI feature. Add all supported T10-PI checksums
+        * as options if T10-PI checksum is enforced. If the T10-PI checksum is
+        * not enforced, only add them as options when speed is good.
+        */
+       if (ofd_t10_cksum_type == 0) {
+               /*
+                * Server allows all T10PI checksums, and server_t10_types
+                * include quick ones.
+                */
+               if (enforce)
+                       *cksum_types |= client_t10_types;
+               else
+                       *cksum_types |= client_t10_types & server_t10_types;
+               return;
+       }
+
+       /*
+        * This OST has T10-PI feature. Disable all other checksum types if
+        * T10-PI checksum is enforced. If the T10-PI checksum is not enforced,
+        * add the checksum type as an option.
+        */
+       if (client_t10_types & ofd_t10_cksum_type) {
+               if (enforce)
+                       *cksum_types = ofd_t10_cksum_type;
+               else
+                       *cksum_types |= ofd_t10_cksum_type;
+       }
+}
+
+/**
  * Match client and OST server connection feature flags.
  *
  * Compute the compatibility flags for a connection request based on
@@ -143,8 +224,8 @@ static int ofd_parse_connect_data(const struct lu_env *env,
                                  struct obd_connect_data *data,
                                  bool new_connection)
 {
-       struct ofd_device                *ofd = ofd_exp(exp);
-       struct filter_export_data        *fed = &exp->exp_filter_data;
+       struct ofd_device *ofd = ofd_exp(exp);
+       struct filter_export_data *fed = &exp->exp_filter_data;
 
        if (!data)
                RETURN(0);
@@ -160,7 +241,7 @@ static int ofd_parse_connect_data(const struct lu_env *env,
                CWARN("!!! This export (nid %s) used object group %d "
                      "earlier; now it's trying to use group %d!  This could "
                      "be a bug in the MDS. Please report to "
-                     "https://jira.hpdd.intel.com/\n",
+                     "https://jira.whamcloud.com/\n",
                      obd_export_nid2str(exp), fed->fed_group,
                      data->ocd_group);
                RETURN(-EPROTO);
@@ -172,8 +253,6 @@ static int ofd_parse_connect_data(const struct lu_env *env,
        if (data->ocd_connect_flags & OBD_CONNECT_FLAGS2)
                data->ocd_connect_flags2 &= OST_CONNECT_SUPPORTED2;
 
-       data->ocd_version = LUSTRE_VERSION_CODE;
-
        /* Kindly make sure the SKIP_ORPHAN flag is from MDS. */
        if (data->ocd_connect_flags & OBD_CONNECT_MDS)
                CDEBUG(D_HA, "%s: Received MDS connection for group %u\n",
@@ -215,12 +294,12 @@ static int ofd_parse_connect_data(const struct lu_env *env,
                data->ocd_grant_max_blks = ddp->ddp_max_extent_blks;
        }
 
-       if (OCD_HAS_FLAG(data, GRANT)) {
-               /* Save connect_data we have so far because tgt_grant_connect()
-                * uses it to calculate grant. */
-               exp->exp_connect_data = *data;
+       /* Save connect_data we have so far because tgt_grant_connect()
+        * uses it to calculate grant, and we want to save the client
+        * version before it is overwritten by LUSTRE_VERSION_CODE. */
+       exp->exp_connect_data = *data;
+       if (OCD_HAS_FLAG(data, GRANT))
                tgt_grant_connect(env, exp, data, new_connection);
-       }
 
        if (data->ocd_connect_flags & OBD_CONNECT_INDEX) {
                struct lr_server_data *lsd = &ofd->ofd_lut.lut_lsd;
@@ -247,10 +326,7 @@ static int ofd_parse_connect_data(const struct lu_env *env,
        if (data->ocd_connect_flags & OBD_CONNECT_CKSUM) {
                __u32 cksum_types = data->ocd_cksum_types;
 
-               /* The client set in ocd_cksum_types the checksum types it
-                * supports. We have to mask off the algorithms that we don't
-                * support */
-               data->ocd_cksum_types &= ofd->ofd_cksum_types_supported;
+               ofd_mask_cksum_types(ofd, &data->ocd_cksum_types);
 
                if (unlikely(data->ocd_cksum_types == 0)) {
                        CERROR("%s: Connect with checksum support but no "
@@ -273,6 +349,8 @@ static int ofd_parse_connect_data(const struct lu_env *env,
        if (data->ocd_connect_flags & OBD_CONNECT_MAXBYTES)
                data->ocd_maxbytes = ofd->ofd_lut.lut_dt_conf.ddp_maxbytes;
 
+       data->ocd_version = LUSTRE_VERSION_CODE;
+
        if (OCD_HAS_FLAG(data, PINGLESS)) {
                if (ptlrpc_pinger_suppress_pings()) {
                        spin_lock(&exp->exp_obd->obd_dev_lock);
@@ -715,7 +793,7 @@ static int ofd_get_info(const struct lu_env *env, struct obd_export *exp,
  * \retval             negative value on error
  */
 int ofd_statfs(const struct lu_env *env,  struct obd_export *exp,
-              struct obd_statfs *osfs, __u64 max_age, __u32 flags)
+              struct obd_statfs *osfs, time64_t max_age, __u32 flags)
 {
         struct obd_device      *obd = class_exp2obd(exp);
        struct ofd_device       *ofd = ofd_exp(exp);
@@ -749,8 +827,9 @@ int ofd_statfs(const struct lu_env *env,  struct obd_export *exp,
                struct tg_export_data *ted;
 
                ted = &obd->obd_self_export->exp_target_data;
-               osfs->os_bavail -= min_t(u64, osfs->os_bavail,
-                                        ted->ted_grant >> tgd->tgd_blockbits);
+               osfs->os_granted = min_t(u64, osfs->os_bavail,
+                                         ted->ted_grant >> tgd->tgd_blockbits);
+               osfs->os_bavail -= osfs->os_granted;
        }
 
        tgt_grant_sanity_check(obd, __func__);
@@ -780,6 +859,7 @@ int ofd_statfs(const struct lu_env *env,  struct obd_export *exp,
                osfs->os_blocks <<= tgd->tgd_blockbits - COMPAT_BSIZE_SHIFT;
                osfs->os_bfree  <<= tgd->tgd_blockbits - COMPAT_BSIZE_SHIFT;
                osfs->os_bavail <<= tgd->tgd_blockbits - COMPAT_BSIZE_SHIFT;
+               osfs->os_granted <<= tgd->tgd_blockbits - COMPAT_BSIZE_SHIFT;
                osfs->os_bsize    = 1 << COMPAT_BSIZE_SHIFT;
        }
 
@@ -818,7 +898,6 @@ static int ofd_echo_setattr(const struct lu_env *env, struct obd_export *exp,
        struct ldlm_resource    *res;
        struct ofd_object       *fo;
        struct lu_fid           *fid = &oa->o_oi.oi_fid;
-       struct filter_fid       *ff = NULL;
        int                      rc = 0;
 
        ENTRY;
@@ -855,13 +934,8 @@ static int ofd_echo_setattr(const struct lu_env *env, struct obd_export *exp,
        la_from_obdo(&info->fti_attr, oa, oa->o_valid);
        info->fti_attr.la_valid &= ~LA_TYPE;
 
-       if (oa->o_valid & OBD_MD_FLFID) {
-               ff = &info->fti_mds_fid;
-               ofd_prepare_fidea(ff, oa);
-       }
-
        /* setting objects attributes (including owner/group) */
-       rc = ofd_attr_set(env, fo, &info->fti_attr, ff);
+       rc = ofd_attr_set(env, fo, &info->fti_attr, oa);
        if (rc)
                GOTO(out_unlock, rc);
 
@@ -891,7 +965,7 @@ out:
  *
  * Supplemental function to destroy object by FID, it is used by request
  * handler and by ofd_echo_destroy() below to find object by FID, lock it
- * and call ofd_object_destroy() finally.
+ * and call ofd_destroy() finally.
  *
  * \param[in] env      execution environment
  * \param[in] ofd      OFD device
@@ -931,7 +1005,7 @@ int ofd_destroy_by_fid(const struct lu_env *env, struct ofd_device *ofd,
 
        LASSERT(fo != NULL);
 
-       rc = ofd_object_destroy(env, fo, orphan);
+       rc = ofd_destroy(env, fo, orphan);
        EXIT;
 
        ofd_object_put(env, fo);
@@ -1011,9 +1085,10 @@ static int ofd_echo_create(const struct lu_env *env, struct obd_export *exp,
        struct ofd_device       *ofd = ofd_exp(exp);
        u64                      seq = ostid_seq(&oa->o_oi);
        struct ofd_seq          *oseq;
-       int                      rc = 0, diff = 1;
        long                     granted;
        u64                      next_id;
+       s64 diff = 1;
+       int rc = 0;
        int                      count;
 
        ENTRY;
@@ -1049,22 +1124,27 @@ static int ofd_echo_create(const struct lu_env *env, struct obd_export *exp,
                rc = granted;
                granted = 0;
                CDEBUG(D_HA, "%s: failed to acquire grant space for "
-                      "precreate (%d): rc = %d\n", ofd_name(ofd), diff, rc);
+                      "precreate (%lld): rc = %d\n", ofd_name(ofd), diff, rc);
                diff = 0;
                GOTO(out, rc);
        }
 
        next_id = ofd_seq_last_oid(oseq) + 1;
-       count = ofd_precreate_batch(ofd, diff);
+       count = ofd_precreate_batch(ofd, (int)diff);
 
        rc = ofd_precreate_objects(env, ofd, next_id, oseq, count, 0);
        if (rc < 0) {
                CERROR("%s: unable to precreate: rc = %d\n",
                       ofd_name(ofd), rc);
        } else {
-               ostid_set_id(&oa->o_oi, ofd_seq_last_oid(oseq));
+               rc = ostid_set_id(&oa->o_oi, ofd_seq_last_oid(oseq));
+               if (rc) {
+                       CERROR("%s: Bad %llu to set " DOSTID " : rc %d\n",
+                              ofd_name(ofd),
+                              (unsigned long long)ofd_seq_last_oid(oseq),
+                              POSTID(&oa->o_oi), rc);
+               }
                oa->o_valid |= OBD_MD_FLID | OBD_MD_FLGROUP;
-               rc = 0;
        }
 
        tgt_grant_commit(ofd_obd(ofd)->obd_self_export, granted, rc);
@@ -1164,10 +1244,12 @@ static int ofd_ioc_get_obj_version(const struct lu_env *env,
                   data->ioc_inllen3 == sizeof(__u64) &&
                   data->ioc_inlbuf4 != NULL &&
                   data->ioc_inllen4 == sizeof(__u64)) {
-               struct ost_id ostid;
+               struct ost_id ostid = { };
 
                ostid_set_seq(&ostid, *(__u64 *)data->ioc_inlbuf4);
-               ostid_set_id(&ostid, *(__u64 *)data->ioc_inlbuf3);
+               rc = ostid_set_id(&ostid, *(__u64 *)data->ioc_inlbuf3);
+               if (rc)
+                       GOTO(out, rc);
                rc = ostid_to_fid(&fid, &ostid,
                                  ofd->ofd_lut.lut_lsd.lsd_osd_index);
                if (rc != 0)