Whamcloud - gitweb
LU-4287 autoconf: Improve test for proc write and read functions
[fs/lustre-release.git] / lustre / fid / fid_handler.c
index 9dff6eb..e3473d5 100644 (file)
@@ -56,9 +56,8 @@
 static void seq_server_proc_fini(struct lu_server_seq *seq);
 
 /* Assigns client to sequence controller node. */
-int seq_server_set_cli(struct lu_server_seq *seq,
-                       struct lu_client_seq *cli,
-                       const struct lu_env *env)
+int seq_server_set_cli(const struct lu_env *env, struct lu_server_seq *seq,
+                      struct lu_client_seq *cli)
 {
         int rc = 0;
         ENTRY;
@@ -153,6 +152,41 @@ int seq_server_alloc_super(struct lu_server_seq *seq,
         RETURN(rc);
 }
 
+int seq_server_alloc_spec(struct lu_server_seq *seq,
+                         struct lu_seq_range *spec,
+                         const struct lu_env *env)
+{
+       struct lu_seq_range *space = &seq->lss_space;
+       int rc = -ENOSPC;
+       ENTRY;
+
+       /*
+        * In some cases (like recovery after a disaster)
+        * we may need to allocate sequences manually
+        * Notice some sequences can be lost if requested
+        * range doesn't start at the beginning of current
+        * free space. Also notice it's not possible now
+        * to allocate sequences out of natural order.
+        */
+       if (spec->lsr_start >= spec->lsr_end)
+               RETURN(-EINVAL);
+       if (spec->lsr_flags != LU_SEQ_RANGE_MDT &&
+           spec->lsr_flags != LU_SEQ_RANGE_OST)
+               RETURN(-EINVAL);
+
+       mutex_lock(&seq->lss_mutex);
+       if (spec->lsr_start >= space->lsr_start) {
+               space->lsr_start = spec->lsr_end;
+               rc = seq_store_update(env, seq, spec, 1 /* sync */);
+
+               LCONSOLE_INFO("%s: "DRANGE" sequences allocated: rc = %d \n",
+                             seq->lss_name, PRANGE(spec), rc);
+       }
+       mutex_unlock(&seq->lss_mutex);
+
+       RETURN(rc);
+}
+
 static int __seq_set_init(const struct lu_env *env,
                             struct lu_server_seq *seq)
 {
@@ -183,8 +217,8 @@ static int __seq_set_init(const struct lu_env *env,
  * flaged as sync write op.
  */
 static int range_alloc_set(const struct lu_env *env,
-                            struct lu_seq_range *out,
-                            struct lu_server_seq *seq)
+                           struct lu_seq_range *out,
+                           struct lu_server_seq *seq)
 {
         struct lu_seq_range *space = &seq->lss_space;
         struct lu_seq_range *loset = &seq->lss_lowater_set;
@@ -255,6 +289,15 @@ static int __seq_server_alloc_meta(struct lu_server_seq *seq,
                /* Saving new range to allocation space. */
                *space = seq->lss_cli->lcs_space;
                LASSERT(range_is_sane(space));
+               if (seq->lss_cli->lcs_srv == NULL) {
+                       struct lu_server_fld *fld;
+
+                       /* Insert it to the local FLDB */
+                       fld = seq->lss_site->ss_server_fld;
+                       mutex_lock(&fld->lsf_lock);
+                       rc = fld_insert_entry(env, fld, space);
+                       mutex_unlock(&fld->lsf_lock);
+               }
        }
 
        rc = range_alloc_set(env, out, seq);
@@ -365,34 +408,45 @@ LU_KEY_INIT_FINI(seq, struct seq_thread_info);
 /* context key: seq_thread_key */
 LU_CONTEXT_KEY_DEFINE(seq, LCT_MD_THREAD | LCT_DT_THREAD);
 
+extern const struct file_operations seq_fld_proc_seq_fops;
+
 static int seq_server_proc_init(struct lu_server_seq *seq)
 {
 #ifdef LPROCFS
+       int rc;
+       ENTRY;
 
-        int rc;
-        ENTRY;
+       seq->lss_proc_dir = lprocfs_seq_register(seq->lss_name,
+                                                seq_type_proc_dir,
+                                                NULL, NULL);
+       if (IS_ERR(seq->lss_proc_dir)) {
+               rc = PTR_ERR(seq->lss_proc_dir);
+               RETURN(rc);
+       }
 
-        seq->lss_proc_dir = lprocfs_register(seq->lss_name,
-                                             seq_type_proc_dir,
-                                             NULL, NULL);
-        if (IS_ERR(seq->lss_proc_dir)) {
-                rc = PTR_ERR(seq->lss_proc_dir);
-                RETURN(rc);
-        }
+       rc = lprocfs_seq_add_vars(seq->lss_proc_dir,
+                                 seq_server_proc_list, seq);
+       if (rc) {
+               CERROR("%s: Can't init sequence manager "
+                      "proc, rc %d\n", seq->lss_name, rc);
+               GOTO(out_cleanup, rc);
+       }
 
-        rc = lprocfs_add_vars(seq->lss_proc_dir,
-                              seq_server_proc_list, seq);
-        if (rc) {
-                CERROR("%s: Can't init sequence manager "
-                       "proc, rc %d\n", seq->lss_name, rc);
-                GOTO(out_cleanup, rc);
-        }
+       if (seq->lss_type == LUSTRE_SEQ_CONTROLLER) {
+               rc = lprocfs_seq_create(seq->lss_proc_dir, "fldb", 0644,
+                                       &seq_fld_proc_seq_fops, seq);
+               if (rc) {
+                       CERROR("%s: Can't create fldb for sequence manager "
+                              "proc: rc = %d\n", seq->lss_name, rc);
+                       GOTO(out_cleanup, rc);
+               }
+       }
 
-        RETURN(0);
+       RETURN(0);
 
 out_cleanup:
-        seq_server_proc_fini(seq);
-        return rc;
+       seq_server_proc_fini(seq);
+       return rc;
 #else /* LPROCFS */
        return 0;
 #endif
@@ -411,21 +465,32 @@ static void seq_server_proc_fini(struct lu_server_seq *seq)
 #endif /* LPROCFS */
 }
 
-int seq_server_init(struct lu_server_seq *seq,
+int seq_server_init(const struct lu_env *env,
+                   struct lu_server_seq *seq,
                    struct dt_device *dev,
                    const char *prefix,
                    enum lu_mgr_type type,
-                   struct seq_server_site *ss,
-                   const struct lu_env *env)
+                   struct seq_server_site *ss)
 {
-        int rc, is_srv = (type == LUSTRE_SEQ_SERVER);
-        ENTRY;
+       int rc, is_srv = (type == LUSTRE_SEQ_SERVER);
+       ENTRY;
 
-        LASSERT(dev != NULL);
-        LASSERT(prefix != NULL);
+       LASSERT(dev != NULL);
+       LASSERT(prefix != NULL);
        LASSERT(ss != NULL);
        LASSERT(ss->ss_lu != NULL);
 
+       /* A compile-time check for FIDs that used to be in lustre_idl.h
+        * but is moved here to remove CLASSERT/LASSERT in that header.
+        * Check all lu_fid fields are converted in fid_cpu_to_le() and friends
+        * and that there is no padding added by compiler to the struct. */
+       {
+               struct lu_fid tst;
+
+               CLASSERT(sizeof(tst) == sizeof(tst.f_seq) +
+                        sizeof(tst.f_oid) + sizeof(tst.f_ver));
+       }
+
        seq->lss_cli = NULL;
        seq->lss_type = type;
        seq->lss_site = ss;
@@ -455,7 +520,6 @@ int seq_server_init(struct lu_server_seq *seq,
                         LUSTRE_SEQ_ZERO_RANGE:
                         LUSTRE_SEQ_SPACE_RANGE;
 
-               LASSERT(ss != NULL);
                seq->lss_space.lsr_index = ss->ss_node_id;
                LCONSOLE_INFO("%s: No data found "
                              "on store. Initialize space\n",