Whamcloud - gitweb
b=22069 replace server_major_version with connect_flags for quota utils interoperability
authorFan Yong <Yong.Fan@Sun.COM>
Wed, 24 Mar 2010 03:38:42 +0000 (11:38 +0800)
committerJohann Lombardi <johann@sun.com>
Wed, 24 Mar 2010 12:24:53 +0000 (13:24 +0100)
replace server_major_version with connect_flags for quota utils interoperability.

i=johann
i=landen

lustre/include/lustre/liblustreapi.h
lustre/include/lustre/lustre_user.h
lustre/llite/dir.c
lustre/utils/lfs.c
lustre/utils/liblustreapi.c

index dd22541..570b852 100644 (file)
@@ -184,4 +184,4 @@ extern int llapi_poll_quotacheck(char *mnt, struct if_quotacheck *qchk);
 extern int llapi_quotactl(char *mnt, struct if_quotactl *qctl);
 extern int llapi_target_iterate(int type_num, char **obd_type, void *args, llapi_cb_t cb);
 #endif
-extern int llapi_server_major_version(const char *mnt);
+extern int llapi_get_connect_flags(const char *mnt, __u64 *flags);
index d99c7c5..fe970b6 100644 (file)
@@ -130,7 +130,7 @@ struct obd_statfs {
 #define LL_IOC_LLOOP_DETACH_BYDEV       _IOWR('f', 169, OBD_IOC_DATA_TYPE)
 
 #define LL_IOC_PATH2FID                 _IOR ('f', 173, long)
-#define LL_IOC_SERVER_MAJOR_VERSION     _IOWR('f', 174, long)
+#define LL_IOC_GET_CONNECT_FLAGS        _IOWR('f', 174, __u64 *)
 
 #define LL_STATFS_MDC           1
 #define LL_STATFS_LOV           2
@@ -383,9 +383,6 @@ struct if_quotactl {
         struct obd_uuid         obd_uuid;
 };
 
-#define SERVER_MAJOR_VERSION_V1 1
-#define SERVER_MAJOR_VERSION_V2 2
-
 #ifndef offsetof
 # define offsetof(typ,memb)     ((unsigned long)((char *)&(((typ *)0)->memb)))
 #endif
index 613848b..0463e04 100644 (file)
@@ -1596,12 +1596,10 @@ static int ll_dir_ioctl(struct inode *inode, struct file *file,
 
                 RETURN(0);
         }
-        case LL_IOC_SERVER_MAJOR_VERSION: {
-                int version = SERVER_MAJOR_VERSION_V1;
-
-                if (sbi->ll_mdc_exp->exp_connect_flags & OBD_CONNECT_FID)
-                        version = SERVER_MAJOR_VERSION_V2;
-                if (copy_to_user((void *)arg, &version, sizeof(int)))
+        case LL_IOC_GET_CONNECT_FLAGS: {
+                if (copy_to_user((void *)arg,
+                                 &sbi->ll_mdc_exp->exp_connect_flags,
+                                 sizeof(__u64)))
                         RETURN(-EFAULT);
                 RETURN(0);
         }
index db85e0c..b6fc00f 100644 (file)
@@ -1273,6 +1273,21 @@ out:
 }
 
 #ifdef HAVE_SYS_QUOTA_H
+static int quota_is_2_0_server(const char *mnt)
+{
+        __u64 flags;
+        int rc;
+
+        rc = llapi_get_connect_flags(mnt, &flags);
+        if (rc < 0)
+                return rc;
+
+        if (flags & OBD_CONNECT_FID)
+                return 1;
+        else
+                return 0;
+}
+
 static int lfs_quotachown(int argc, char **argv)
 {
 
@@ -1307,7 +1322,7 @@ static int lfs_quotacheck(int argc, char **argv)
         struct if_quotactl qctl;
         char *obd_type = (char *)qchk.obd_type;
         int rc;
-        int version;
+        int v2;
 
         optind = 0;
         while ((c = getopt(argc, argv, "ug")) != -1) {
@@ -1334,12 +1349,12 @@ static int lfs_quotacheck(int argc, char **argv)
                 return CMD_HELP;
 
         mnt = argv[optind];
-        version = llapi_server_major_version(mnt);
-        if (version < 0)
-                return version;
+        v2 = quota_is_2_0_server(mnt);
+        if (v2 < 0)
+                return v2;
 
         /* For b1_8 server */
-        if (version < SERVER_MAJOR_VERSION_V2) {
+        if (v2 == 0) {
                 memset(&qctl, 0, sizeof(qctl));
                 qctl.qc_cmd = LUSTRE_Q_QUOTAOFF;
                 qctl.qc_type = check_type;
@@ -1371,12 +1386,12 @@ static int lfs_quotacheck(int argc, char **argv)
         memset(&qctl, 0, sizeof(qctl));
         qctl.qc_cmd = LUSTRE_Q_QUOTAON;
         qctl.qc_type = check_type;
-        if (version < SERVER_MAJOR_VERSION_V2)
+        if (v2 == 0)
                 qctl.qc_id = QFMT_LDISKFS; /* compatibility: 1.6.5 and earliers
                                             * take this parameter into account */
         rc = llapi_quotactl(mnt, &qctl);
         if (rc) {
-                if (version >= SERVER_MAJOR_VERSION_V2 && errno == EALREADY) {
+                if (v2 > 0 && errno == EALREADY) {
                         /* This is for 2.0 server. */
                         rc = 0;
                 } else {
@@ -1398,7 +1413,7 @@ static int lfs_quotaon(int argc, char **argv)
         struct if_quotactl qctl;
         char *obd_type = (char *)qctl.obd_type;
         int rc;
-        int version;
+        int v2;
 
         memset(&qctl, 0, sizeof(qctl));
         qctl.qc_cmd = LUSTRE_Q_QUOTAON;
@@ -1431,20 +1446,18 @@ static int lfs_quotaon(int argc, char **argv)
                 return CMD_HELP;
 
         mnt = argv[optind];
-        version = llapi_server_major_version(mnt);
-        if (version < 0)
-                return version;
+        v2 = quota_is_2_0_server(mnt);
+        if (v2 < 0)
+                return v2;
 
-        if (version < SERVER_MAJOR_VERSION_V2)
+        if (v2 == 0)
                 qctl.qc_id = QFMT_LDISKFS; /* compatibility: 1.6.5 and earliers
                                             * take this parameter into account */
 
         rc = llapi_quotactl(mnt, &qctl);
         if (rc) {
-                if (version >= SERVER_MAJOR_VERSION_V2 && errno == EALREADY) {
+                if (v2 > 0 && errno == EALREADY) {
                         /* This is for 2.0 server. */
-                        fprintf(stderr, "\n%s quotas are enabled already.\n",
-                                qctl.qc_type == 0x00 ? "user" : "group");
                         rc = 0;
                 } else if (errno == ENOENT) {
                         fprintf(stderr, "error: cannot find quota database, "
@@ -1468,7 +1481,7 @@ static int lfs_quotaoff(int argc, char **argv)
         struct if_quotactl qctl;
         char *obd_type = (char *)qctl.obd_type;
         int rc;
-        int version;
+        int v2;
 
         memset(&qctl, 0, sizeof(qctl));
         qctl.qc_cmd = LUSTRE_Q_QUOTAOFF;
@@ -1498,16 +1511,14 @@ static int lfs_quotaoff(int argc, char **argv)
                 return CMD_HELP;
 
         mnt = argv[optind];
-        version = llapi_server_major_version(mnt);
-        if (version < 0)
-                return version;
+        v2 = quota_is_2_0_server(mnt);
+        if (v2 < 0)
+                return v2;
 
         rc = llapi_quotactl(mnt, &qctl);
         if (rc) {
-                if ((version >= SERVER_MAJOR_VERSION_V2 && errno == EALREADY) ||
-                    (version < SERVER_MAJOR_VERSION_V2 && errno == ESRCH)) {
-                        fprintf(stderr, "\n%s quotas are not enabled.\n",
-                                qctl.qc_type == 0x00 ? "user" : "group");
+                if ((v2 > 0 && errno == EALREADY) ||
+                    (v2 == 0 && errno == ESRCH)) {
                         rc = 0;
                 } else {
                         if (*obd_type)
@@ -2191,7 +2202,6 @@ static int lfs_quota(int argc, char **argv)
         int rc, rc1 = 0, rc2 = 0, rc3 = 0, verbose = 0, inacc, quiet = 0;
         int pass = 0;
         char *endptr;
-        int version;
 
         optind = 0;
         while ((c = getopt(argc, argv, "ugto:qv")) != -1) {
@@ -2271,9 +2281,6 @@ ug_output:
         }
 
         mnt = argv[optind];
-        version = llapi_server_major_version(mnt);
-        if (version < 0)
-                goto out;
 
         rc1 = llapi_quotactl(mnt, &qctl);
         if (rc1 == -1) {
@@ -2283,16 +2290,11 @@ ug_output:
                 case ENOENT:
                         /* We already got a "No such file..." message. */
                         goto out;
-                case EALREADY:
-                case ESRCH:
-                        if ((version >= SERVER_MAJOR_VERSION_V2 &&
-                             errno == EALREADY) ||
-                            (version < SERVER_MAJOR_VERSION_V2 &&
-                             errno == ESRCH)) {
-                                fprintf(stderr, "%s quotas are not enabled.\n",
-                                        qctl.qc_type == USRQUOTA?"user":"group");
-                                goto out;
-                        }
+                case ESRCH: {
+                        fprintf(stderr, "%s quotas are not enabled.\n",
+                                qctl.qc_type == USRQUOTA?"user":"group");
+                        goto out;
+                }
                 default:
                         fprintf(stderr, "Unexpected quotactl error: %s\n",
                                 strerror(errno));
index 205ab72..65ea002 100644 (file)
@@ -2400,10 +2400,10 @@ int llapi_path2fid(const char *path, lustre_fid *fid)
         return rc;
 }
 
-int llapi_server_major_version(const char *mnt)
+int llapi_get_connect_flags(const char *mnt, __u64 *flags)
 {
         DIR *root;
-        int ver = 0, rc;
+        int rc;
 
         root = opendir(mnt);
         if (!root) {
@@ -2411,12 +2411,10 @@ int llapi_server_major_version(const char *mnt)
                 return -1;
         }
 
-        rc = ioctl(dirfd(root), LL_IOC_SERVER_MAJOR_VERSION, &ver);
+        rc = ioctl(dirfd(root), LL_IOC_GET_CONNECT_FLAGS, flags);
         closedir(root);
-        if (rc < 0) {
+        if (rc < 0)
                 llapi_err(LLAPI_MSG_ERROR,
-                          "ioctl on %s for server major version failed", mnt);
-                return rc;
-        }
-        return ver;
+                          "ioctl on %s for getting connect flags failed", mnt);
+        return rc;
 }