Whamcloud - gitweb
Revert "LU-5417 lfs: fix comparison between signed and unsigned"
[fs/lustre-release.git] / lustre / include / lustre / lustre_user.h
index 28846c7..bb808e8 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2010, 2013, Intel Corporation.
+ * Copyright (c) 2010, 2014, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
 #include <libcfs/types.h>
 
 #ifdef __KERNEL__
+# include <linux/quota.h>
 # include <linux/string.h> /* snprintf() */
-#else
+# include <linux/version.h>
+#else /* !__KERNEL__ */
+# define NEED_QUOTA_DEFS
 # include <stdio.h> /* snprintf() */
-#endif
+# include <string.h>
+# include <sys/quota.h>
+# include <sys/stat.h>
+#endif /* __KERNEL__ */
 #include <lustre/ll_fiemap.h>
-#include <linux/lustre_user.h>
+
+#if defined(__x86_64__) || defined(__ia64__) || defined(__ppc64__) || \
+    defined(__craynv) || defined(__mips64__) || defined(__powerpc64__)
+typedef struct stat    lstat_t;
+# define lstat_f       lstat
+# define HAVE_LOV_USER_MDS_DATA
+#elif defined(__USE_LARGEFILE64) || defined(__KERNEL__)
+typedef struct stat64  lstat_t;
+# define lstat_f       lstat64
+# define HAVE_LOV_USER_MDS_DATA
+#endif
 
 #define LUSTRE_EOF 0xffffffffffffffffULL
 
@@ -928,39 +944,64 @@ static inline char *changelog_rec_sname(struct changelog_rec *rec)
        return cr_name + strlen(cr_name) + 1;
 }
 
-/* Remap a record to the desired format as specified by the crf flags.
- * The record must be big enough to contain the final remapped version. */
+/**
+ * Remap a record to the desired format as specified by the crf flags.
+ * The record must be big enough to contain the final remapped version.
+ * Superfluous extension fields are removed and missing ones are added
+ * and zeroed. The flags of the record are updated accordingly.
+ *
+ * The jobid and rename extensions can be added to a record, to match the
+ * format an application expects, typically. In this case, the newly added
+ * fields will be zeroed.
+ * The Jobid field can be removed, to guarantee compatibility with older
+ * clients that don't expect this field in the records they process.
+ *
+ * The following assumptions are being made:
+ *   - CLF_RENAME will not be removed
+ *   - CLF_JOBID will not be added without CLF_RENAME being added too
+ *
+ * @param[in,out]  rec         The record to remap.
+ * @param[in]      crf_wanted  Flags describing the desired extensions.
+ */
 static inline void changelog_remap_rec(struct changelog_rec *rec,
-                                      enum changelog_rec_flags crf)
+                                      enum changelog_rec_flags crf_wanted)
 {
-       char    *var_part;
-       size_t   var_size;
+       char *jid_mov;
+       char *rnm_mov;
 
-       crf &= CLF_SUPPORTED;
+       crf_wanted &= CLF_SUPPORTED;
 
-       if ((rec->cr_flags & CLF_SUPPORTED) == crf)
+       if ((rec->cr_flags & CLF_SUPPORTED) == crf_wanted)
                return;
 
-       if ((crf & CLF_JOBID) && rec->cr_flags & CLF_JOBID) {
-               var_part = (char *)changelog_rec_jobid(rec);
-               var_size = rec->cr_namelen + sizeof(struct changelog_ext_jobid);
-       } else {
-               var_part = changelog_rec_name(rec);
-               var_size = rec->cr_namelen;
-       }
+       /* First move the variable-length name field */
+       memmove((char *)rec + changelog_rec_offset(crf_wanted),
+               changelog_rec_name(rec), rec->cr_namelen);
+
+       /* Locations of jobid and rename extensions in the remapped record */
+       jid_mov = (char *)rec +
+                 changelog_rec_offset(crf_wanted & ~CLF_JOBID);
+       rnm_mov = (char *)rec +
+                 changelog_rec_offset(crf_wanted & ~(CLF_JOBID | CLF_RENAME));
+
+       /* Move the extension fields to the desired positions */
+       if ((crf_wanted & CLF_JOBID) && (rec->cr_flags & CLF_JOBID))
+               memmove(jid_mov, changelog_rec_jobid(rec),
+                       sizeof(struct changelog_ext_jobid));
 
-       memmove((char *)rec + changelog_rec_offset(crf & ~CLF_JOBID), var_part,
-               var_size);
+       if ((crf_wanted & CLF_RENAME) && (rec->cr_flags & CLF_RENAME))
+               memmove(rnm_mov, changelog_rec_rename(rec),
+                       sizeof(struct changelog_ext_rename));
 
-       if ((crf & CLF_RENAME) && !(rec->cr_flags & CLF_RENAME))
-               memset(changelog_rec_rename(rec), 0,
-                      sizeof(struct changelog_ext_rename));
+       /* Clear newly added fields */
+       if ((crf_wanted & CLF_JOBID) && !(rec->cr_flags & CLF_JOBID))
+               memset(jid_mov, 0, sizeof(struct changelog_ext_jobid));
 
-       if ((crf & CLF_JOBID) && !(rec->cr_flags & CLF_JOBID))
-               memset(changelog_rec_jobid(rec), 0,
-                      sizeof(struct changelog_ext_jobid));
+       if ((crf_wanted & CLF_RENAME) && !(rec->cr_flags & CLF_RENAME))
+               memset(rnm_mov, 0, sizeof(struct changelog_ext_rename));
 
-       rec->cr_flags = (rec->cr_flags & CLF_FLAGMASK) | crf;
+       /* Update the record's flags accordingly */
+       rec->cr_flags = (rec->cr_flags & CLF_FLAGMASK) | crf_wanted;
 }
 
 struct ioc_changelog {
@@ -1156,7 +1197,7 @@ static inline ssize_t hur_len(struct hsm_user_request *hur)
                (__u64)hur->hur_request.hr_itemcount *
                sizeof(hur->hur_user_item[0]) + hur->hur_request.hr_data_len;
 
-       if (size > ~((size_t)0)>>1)
+       if (size != (ssize_t)size)
                return -1;
 
        return size;