mount.c 5.4 KB

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