mount.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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 <linux/parser.h>
  16. #include "gfs2.h"
  17. #include "incore.h"
  18. #include "mount.h"
  19. #include "sys.h"
  20. #include "util.h"
  21. enum {
  22. Opt_lockproto,
  23. Opt_locktable,
  24. Opt_hostdata,
  25. Opt_spectator,
  26. Opt_ignore_local_fs,
  27. Opt_localflocks,
  28. Opt_localcaching,
  29. Opt_debug,
  30. Opt_nodebug,
  31. Opt_upgrade,
  32. Opt_num_glockd,
  33. Opt_acl,
  34. Opt_noacl,
  35. Opt_quota_off,
  36. Opt_quota_account,
  37. Opt_quota_on,
  38. Opt_suiddir,
  39. Opt_nosuiddir,
  40. Opt_data_writeback,
  41. Opt_data_ordered,
  42. };
  43. static match_table_t tokens = {
  44. {Opt_lockproto, "lockproto=%s"},
  45. {Opt_locktable, "locktable=%s"},
  46. {Opt_hostdata, "hostdata=%s"},
  47. {Opt_spectator, "spectator"},
  48. {Opt_ignore_local_fs, "ignore_local_fs"},
  49. {Opt_localflocks, "localflocks"},
  50. {Opt_localcaching, "localcaching"},
  51. {Opt_debug, "debug"},
  52. {Opt_nodebug, "nodebug"},
  53. {Opt_upgrade, "upgrade"},
  54. {Opt_num_glockd, "num_glockd=%d"},
  55. {Opt_acl, "acl"},
  56. {Opt_noacl, "noacl"},
  57. {Opt_quota_off, "quota=off"},
  58. {Opt_quota_account, "quota=account"},
  59. {Opt_quota_on, "quota=on"},
  60. {Opt_suiddir, "suiddir"},
  61. {Opt_nosuiddir, "nosuiddir"},
  62. {Opt_data_writeback, "data=writeback"},
  63. {Opt_data_ordered, "data=ordered"}
  64. };
  65. /**
  66. * gfs2_mount_args - Parse mount options
  67. * @sdp:
  68. * @data:
  69. *
  70. * Return: errno
  71. */
  72. int gfs2_mount_args(struct gfs2_sbd *sdp, char *data_arg, int remount)
  73. {
  74. struct gfs2_args *args = &sdp->sd_args;
  75. char *data = data_arg;
  76. char *options, *o, *v;
  77. int error = 0;
  78. /* If someone preloaded options, use those instead */
  79. spin_lock(&gfs2_sys_margs_lock);
  80. if (!remount && gfs2_sys_margs) {
  81. data = gfs2_sys_margs;
  82. gfs2_sys_margs = NULL;
  83. }
  84. spin_unlock(&gfs2_sys_margs_lock);
  85. /* Set some defaults */
  86. memset(args, 0, sizeof(struct gfs2_args));
  87. args->ar_num_glockd = GFS2_GLOCKD_DEFAULT;
  88. args->ar_quota = GFS2_QUOTA_DEFAULT;
  89. args->ar_data = GFS2_DATA_DEFAULT;
  90. /* Split the options into tokens with the "," character and
  91. process them */
  92. for (options = data; (o = strsep(&options, ",")); ) {
  93. int token, option;
  94. substring_t tmp[MAX_OPT_ARGS];
  95. if (!*o)
  96. continue;
  97. token = match_token(o, tokens, tmp);
  98. switch (token) {
  99. case Opt_lockproto:
  100. v = match_strdup(&tmp[0]);
  101. if (!v) {
  102. fs_info(sdp, "no memory for lockproto\n");
  103. error = -ENOMEM;
  104. goto out_error;
  105. }
  106. if (remount && strcmp(v, args->ar_lockproto)) {
  107. kfree(v);
  108. goto cant_remount;
  109. }
  110. strncpy(args->ar_lockproto, v, GFS2_LOCKNAME_LEN);
  111. args->ar_lockproto[GFS2_LOCKNAME_LEN - 1] = 0;
  112. kfree(v);
  113. break;
  114. case Opt_locktable:
  115. v = match_strdup(&tmp[0]);
  116. if (!v) {
  117. fs_info(sdp, "no memory for locktable\n");
  118. error = -ENOMEM;
  119. goto out_error;
  120. }
  121. if (remount && strcmp(v, args->ar_locktable)) {
  122. kfree(v);
  123. goto cant_remount;
  124. }
  125. strncpy(args->ar_locktable, v, GFS2_LOCKNAME_LEN);
  126. args->ar_locktable[GFS2_LOCKNAME_LEN - 1] = 0;
  127. kfree(v);
  128. break;
  129. case Opt_hostdata:
  130. v = match_strdup(&tmp[0]);
  131. if (!v) {
  132. fs_info(sdp, "no memory for hostdata\n");
  133. error = -ENOMEM;
  134. goto out_error;
  135. }
  136. if (remount && strcmp(v, args->ar_hostdata)) {
  137. kfree(v);
  138. goto cant_remount;
  139. }
  140. strncpy(args->ar_hostdata, v, GFS2_LOCKNAME_LEN);
  141. args->ar_hostdata[GFS2_LOCKNAME_LEN - 1] = 0;
  142. kfree(v);
  143. break;
  144. case Opt_spectator:
  145. if (remount && !args->ar_spectator)
  146. goto cant_remount;
  147. args->ar_spectator = 1;
  148. sdp->sd_vfs->s_flags |= MS_RDONLY;
  149. break;
  150. case Opt_ignore_local_fs:
  151. if (remount && !args->ar_ignore_local_fs)
  152. goto cant_remount;
  153. args->ar_ignore_local_fs = 1;
  154. break;
  155. case Opt_localflocks:
  156. if (remount && !args->ar_localflocks)
  157. goto cant_remount;
  158. args->ar_localflocks = 1;
  159. break;
  160. case Opt_localcaching:
  161. if (remount && !args->ar_localcaching)
  162. goto cant_remount;
  163. args->ar_localcaching = 1;
  164. break;
  165. case Opt_debug:
  166. args->ar_debug = 1;
  167. break;
  168. case Opt_nodebug:
  169. args->ar_debug = 0;
  170. break;
  171. case Opt_upgrade:
  172. if (remount && !args->ar_upgrade)
  173. goto cant_remount;
  174. args->ar_upgrade = 1;
  175. break;
  176. case Opt_num_glockd:
  177. if ((error = match_int(&tmp[0], &option))) {
  178. fs_info(sdp, "problem getting num_glockd\n");
  179. goto out_error;
  180. }
  181. if (remount && option != args->ar_num_glockd)
  182. goto cant_remount;
  183. if (!option || option > GFS2_GLOCKD_MAX) {
  184. fs_info(sdp, "0 < num_glockd <= %u (not %u)\n",
  185. GFS2_GLOCKD_MAX, option);
  186. error = -EINVAL;
  187. goto out_error;
  188. }
  189. args->ar_num_glockd = option;
  190. break;
  191. case Opt_acl:
  192. args->ar_posix_acl = 1;
  193. sdp->sd_vfs->s_flags |= MS_POSIXACL;
  194. break;
  195. case Opt_noacl:
  196. args->ar_posix_acl = 0;
  197. sdp->sd_vfs->s_flags &= ~MS_POSIXACL;
  198. break;
  199. case Opt_quota_off:
  200. args->ar_quota = GFS2_QUOTA_OFF;
  201. break;
  202. case Opt_quota_account:
  203. args->ar_quota = GFS2_QUOTA_ACCOUNT;
  204. break;
  205. case Opt_quota_on:
  206. args->ar_quota = GFS2_QUOTA_ON;
  207. break;
  208. case Opt_suiddir:
  209. args->ar_suiddir = 1;
  210. break;
  211. case Opt_nosuiddir:
  212. args->ar_suiddir = 0;
  213. break;
  214. case Opt_data_writeback:
  215. args->ar_data = GFS2_DATA_WRITEBACK;
  216. break;
  217. case Opt_data_ordered:
  218. args->ar_data = GFS2_DATA_ORDERED;
  219. break;
  220. default:
  221. fs_info(sdp, "unknown option: %s\n", o);
  222. error = -EINVAL;
  223. goto out_error;
  224. }
  225. }
  226. out_error:
  227. if (error)
  228. fs_info(sdp, "invalid mount option(s)\n");
  229. if (data != data_arg)
  230. kfree(data);
  231. return error;
  232. cant_remount:
  233. fs_info(sdp, "can't remount with option %s\n", o);
  234. return -EINVAL;
  235. }