mount.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. * Copyright (C) Sistina Software, Inc. 1997-2003 All rights reserved.
  3. * Copyright (C) 2004-2006 Red Hat, Inc. All rights reserved.
  4. *
  5. * This copyrighted material is made available to anyone wishing to use,
  6. * modify, copy, or redistribute it subject to the terms and conditions
  7. * of the GNU General Public License version 2.
  8. */
  9. #include <linux/slab.h>
  10. #include <linux/spinlock.h>
  11. #include <linux/completion.h>
  12. #include <linux/buffer_head.h>
  13. #include <linux/gfs2_ondisk.h>
  14. #include <linux/lm_interface.h>
  15. #include "gfs2.h"
  16. #include "incore.h"
  17. #include "mount.h"
  18. #include "sys.h"
  19. #include "util.h"
  20. /**
  21. * gfs2_mount_args - Parse mount options
  22. * @sdp:
  23. * @data:
  24. *
  25. * Return: errno
  26. */
  27. int gfs2_mount_args(struct gfs2_sbd *sdp, char *data_arg, int remount)
  28. {
  29. struct gfs2_args *args = &sdp->sd_args;
  30. char *data = data_arg;
  31. char *options, *o, *v;
  32. int error = 0;
  33. if (!remount) {
  34. /* If someone preloaded options, use those instead */
  35. spin_lock(&gfs2_sys_margs_lock);
  36. if (gfs2_sys_margs) {
  37. data = gfs2_sys_margs;
  38. gfs2_sys_margs = NULL;
  39. }
  40. spin_unlock(&gfs2_sys_margs_lock);
  41. /* Set some defaults */
  42. args->ar_num_glockd = GFS2_GLOCKD_DEFAULT;
  43. args->ar_quota = GFS2_QUOTA_DEFAULT;
  44. args->ar_data = GFS2_DATA_DEFAULT;
  45. }
  46. /* Split the options into tokens with the "," character and
  47. process them */
  48. for (options = data; (o = strsep(&options, ",")); ) {
  49. if (!*o)
  50. continue;
  51. v = strchr(o, '=');
  52. if (v)
  53. *v++ = 0;
  54. if (!strcmp(o, "lockproto")) {
  55. if (!v)
  56. goto need_value;
  57. if (remount && strcmp(v, args->ar_lockproto))
  58. goto cant_remount;
  59. strncpy(args->ar_lockproto, v, GFS2_LOCKNAME_LEN);
  60. args->ar_lockproto[GFS2_LOCKNAME_LEN - 1] = 0;
  61. }
  62. else if (!strcmp(o, "locktable")) {
  63. if (!v)
  64. goto need_value;
  65. if (remount && strcmp(v, args->ar_locktable))
  66. goto cant_remount;
  67. strncpy(args->ar_locktable, v, GFS2_LOCKNAME_LEN);
  68. args->ar_locktable[GFS2_LOCKNAME_LEN - 1] = 0;
  69. }
  70. else if (!strcmp(o, "hostdata")) {
  71. if (!v)
  72. goto need_value;
  73. if (remount && strcmp(v, args->ar_hostdata))
  74. goto cant_remount;
  75. strncpy(args->ar_hostdata, v, GFS2_LOCKNAME_LEN);
  76. args->ar_hostdata[GFS2_LOCKNAME_LEN - 1] = 0;
  77. }
  78. else if (!strcmp(o, "spectator")) {
  79. if (remount && !args->ar_spectator)
  80. goto cant_remount;
  81. args->ar_spectator = 1;
  82. sdp->sd_vfs->s_flags |= MS_RDONLY;
  83. }
  84. else if (!strcmp(o, "ignore_local_fs")) {
  85. if (remount && !args->ar_ignore_local_fs)
  86. goto cant_remount;
  87. args->ar_ignore_local_fs = 1;
  88. }
  89. else if (!strcmp(o, "localflocks")) {
  90. if (remount && !args->ar_localflocks)
  91. goto cant_remount;
  92. args->ar_localflocks = 1;
  93. }
  94. else if (!strcmp(o, "localcaching")) {
  95. if (remount && !args->ar_localcaching)
  96. goto cant_remount;
  97. args->ar_localcaching = 1;
  98. }
  99. else if (!strcmp(o, "debug"))
  100. args->ar_debug = 1;
  101. else if (!strcmp(o, "nodebug"))
  102. args->ar_debug = 0;
  103. else if (!strcmp(o, "upgrade")) {
  104. if (remount && !args->ar_upgrade)
  105. goto cant_remount;
  106. args->ar_upgrade = 1;
  107. }
  108. else if (!strcmp(o, "num_glockd")) {
  109. unsigned int x;
  110. if (!v)
  111. goto need_value;
  112. sscanf(v, "%u", &x);
  113. if (remount && x != args->ar_num_glockd)
  114. goto cant_remount;
  115. if (!x || x > GFS2_GLOCKD_MAX) {
  116. fs_info(sdp, "0 < num_glockd <= %u (not %u)\n",
  117. GFS2_GLOCKD_MAX, x);
  118. error = -EINVAL;
  119. break;
  120. }
  121. args->ar_num_glockd = x;
  122. }
  123. else if (!strcmp(o, "acl")) {
  124. args->ar_posix_acl = 1;
  125. sdp->sd_vfs->s_flags |= MS_POSIXACL;
  126. }
  127. else if (!strcmp(o, "noacl")) {
  128. args->ar_posix_acl = 0;
  129. sdp->sd_vfs->s_flags &= ~MS_POSIXACL;
  130. }
  131. else if (!strcmp(o, "quota")) {
  132. if (!v)
  133. goto need_value;
  134. if (!strcmp(v, "off"))
  135. args->ar_quota = GFS2_QUOTA_OFF;
  136. else if (!strcmp(v, "account"))
  137. args->ar_quota = GFS2_QUOTA_ACCOUNT;
  138. else if (!strcmp(v, "on"))
  139. args->ar_quota = GFS2_QUOTA_ON;
  140. else {
  141. fs_info(sdp, "invalid value for quota\n");
  142. error = -EINVAL;
  143. break;
  144. }
  145. }
  146. else if (!strcmp(o, "suiddir"))
  147. args->ar_suiddir = 1;
  148. else if (!strcmp(o, "nosuiddir"))
  149. args->ar_suiddir = 0;
  150. else if (!strcmp(o, "data")) {
  151. if (!v)
  152. goto need_value;
  153. if (!strcmp(v, "writeback"))
  154. args->ar_data = GFS2_DATA_WRITEBACK;
  155. else if (!strcmp(v, "ordered"))
  156. args->ar_data = GFS2_DATA_ORDERED;
  157. else {
  158. fs_info(sdp, "invalid value for data\n");
  159. error = -EINVAL;
  160. break;
  161. }
  162. }
  163. else {
  164. fs_info(sdp, "unknown option: %s\n", o);
  165. error = -EINVAL;
  166. break;
  167. }
  168. }
  169. if (error)
  170. fs_info(sdp, "invalid mount option(s)\n");
  171. if (data != data_arg)
  172. kfree(data);
  173. return error;
  174. need_value:
  175. fs_info(sdp, "need value for option %s\n", o);
  176. return -EINVAL;
  177. cant_remount:
  178. fs_info(sdp, "can't remount with option %s\n", o);
  179. return -EINVAL;
  180. }