mount.c 4.6 KB

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