super.c 66 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591
  1. /* -*- mode: c; c-basic-offset: 8; -*-
  2. * vim: noexpandtab sw=8 ts=8 sts=0:
  3. *
  4. * super.c
  5. *
  6. * load/unload driver, mount/dismount volumes
  7. *
  8. * Copyright (C) 2002, 2004 Oracle. All rights reserved.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2 of the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public
  21. * License along with this program; if not, write to the
  22. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  23. * Boston, MA 021110-1307, USA.
  24. */
  25. #include <linux/module.h>
  26. #include <linux/fs.h>
  27. #include <linux/types.h>
  28. #include <linux/slab.h>
  29. #include <linux/highmem.h>
  30. #include <linux/init.h>
  31. #include <linux/random.h>
  32. #include <linux/statfs.h>
  33. #include <linux/moduleparam.h>
  34. #include <linux/blkdev.h>
  35. #include <linux/socket.h>
  36. #include <linux/inet.h>
  37. #include <linux/parser.h>
  38. #include <linux/crc32.h>
  39. #include <linux/debugfs.h>
  40. #include <linux/mount.h>
  41. #include <linux/seq_file.h>
  42. #include <linux/quotaops.h>
  43. #include <linux/smp_lock.h>
  44. #define MLOG_MASK_PREFIX ML_SUPER
  45. #include <cluster/masklog.h>
  46. #include "ocfs2.h"
  47. /* this should be the only file to include a version 1 header */
  48. #include "ocfs1_fs_compat.h"
  49. #include "alloc.h"
  50. #include "blockcheck.h"
  51. #include "dlmglue.h"
  52. #include "export.h"
  53. #include "extent_map.h"
  54. #include "heartbeat.h"
  55. #include "inode.h"
  56. #include "journal.h"
  57. #include "localalloc.h"
  58. #include "namei.h"
  59. #include "slot_map.h"
  60. #include "super.h"
  61. #include "sysfile.h"
  62. #include "uptodate.h"
  63. #include "ver.h"
  64. #include "xattr.h"
  65. #include "quota.h"
  66. #include "refcounttree.h"
  67. #include "suballoc.h"
  68. #include "buffer_head_io.h"
  69. static struct kmem_cache *ocfs2_inode_cachep = NULL;
  70. struct kmem_cache *ocfs2_dquot_cachep;
  71. struct kmem_cache *ocfs2_qf_chunk_cachep;
  72. /* OCFS2 needs to schedule several differnt types of work which
  73. * require cluster locking, disk I/O, recovery waits, etc. Since these
  74. * types of work tend to be heavy we avoid using the kernel events
  75. * workqueue and schedule on our own. */
  76. struct workqueue_struct *ocfs2_wq = NULL;
  77. static struct dentry *ocfs2_debugfs_root = NULL;
  78. MODULE_AUTHOR("Oracle");
  79. MODULE_LICENSE("GPL");
  80. struct mount_options
  81. {
  82. unsigned long commit_interval;
  83. unsigned long mount_opt;
  84. unsigned int atime_quantum;
  85. signed short slot;
  86. int localalloc_opt;
  87. unsigned int resv_level;
  88. int dir_resv_level;
  89. char cluster_stack[OCFS2_STACK_LABEL_LEN + 1];
  90. };
  91. static int ocfs2_parse_options(struct super_block *sb, char *options,
  92. struct mount_options *mopt,
  93. int is_remount);
  94. static int ocfs2_check_set_options(struct super_block *sb,
  95. struct mount_options *options);
  96. static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt);
  97. static void ocfs2_put_super(struct super_block *sb);
  98. static int ocfs2_mount_volume(struct super_block *sb);
  99. static int ocfs2_remount(struct super_block *sb, int *flags, char *data);
  100. static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err);
  101. static int ocfs2_initialize_mem_caches(void);
  102. static void ocfs2_free_mem_caches(void);
  103. static void ocfs2_delete_osb(struct ocfs2_super *osb);
  104. static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf);
  105. static int ocfs2_sync_fs(struct super_block *sb, int wait);
  106. static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb);
  107. static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb);
  108. static void ocfs2_release_system_inodes(struct ocfs2_super *osb);
  109. static int ocfs2_check_volume(struct ocfs2_super *osb);
  110. static int ocfs2_verify_volume(struct ocfs2_dinode *di,
  111. struct buffer_head *bh,
  112. u32 sectsize,
  113. struct ocfs2_blockcheck_stats *stats);
  114. static int ocfs2_initialize_super(struct super_block *sb,
  115. struct buffer_head *bh,
  116. int sector_size,
  117. struct ocfs2_blockcheck_stats *stats);
  118. static int ocfs2_get_sector(struct super_block *sb,
  119. struct buffer_head **bh,
  120. int block,
  121. int sect_size);
  122. static struct inode *ocfs2_alloc_inode(struct super_block *sb);
  123. static void ocfs2_destroy_inode(struct inode *inode);
  124. static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend);
  125. static int ocfs2_enable_quotas(struct ocfs2_super *osb);
  126. static void ocfs2_disable_quotas(struct ocfs2_super *osb);
  127. static const struct super_operations ocfs2_sops = {
  128. .statfs = ocfs2_statfs,
  129. .alloc_inode = ocfs2_alloc_inode,
  130. .destroy_inode = ocfs2_destroy_inode,
  131. .drop_inode = ocfs2_drop_inode,
  132. .clear_inode = ocfs2_clear_inode,
  133. .delete_inode = ocfs2_delete_inode,
  134. .sync_fs = ocfs2_sync_fs,
  135. .put_super = ocfs2_put_super,
  136. .remount_fs = ocfs2_remount,
  137. .show_options = ocfs2_show_options,
  138. .quota_read = ocfs2_quota_read,
  139. .quota_write = ocfs2_quota_write,
  140. };
  141. enum {
  142. Opt_barrier,
  143. Opt_err_panic,
  144. Opt_err_ro,
  145. Opt_intr,
  146. Opt_nointr,
  147. Opt_hb_none,
  148. Opt_hb_local,
  149. Opt_data_ordered,
  150. Opt_data_writeback,
  151. Opt_atime_quantum,
  152. Opt_slot,
  153. Opt_commit,
  154. Opt_localalloc,
  155. Opt_localflocks,
  156. Opt_stack,
  157. Opt_user_xattr,
  158. Opt_nouser_xattr,
  159. Opt_inode64,
  160. Opt_acl,
  161. Opt_noacl,
  162. Opt_usrquota,
  163. Opt_grpquota,
  164. Opt_resv_level,
  165. Opt_dir_resv_level,
  166. Opt_err,
  167. };
  168. static const match_table_t tokens = {
  169. {Opt_barrier, "barrier=%u"},
  170. {Opt_err_panic, "errors=panic"},
  171. {Opt_err_ro, "errors=remount-ro"},
  172. {Opt_intr, "intr"},
  173. {Opt_nointr, "nointr"},
  174. {Opt_hb_none, OCFS2_HB_NONE},
  175. {Opt_hb_local, OCFS2_HB_LOCAL},
  176. {Opt_data_ordered, "data=ordered"},
  177. {Opt_data_writeback, "data=writeback"},
  178. {Opt_atime_quantum, "atime_quantum=%u"},
  179. {Opt_slot, "preferred_slot=%u"},
  180. {Opt_commit, "commit=%u"},
  181. {Opt_localalloc, "localalloc=%d"},
  182. {Opt_localflocks, "localflocks"},
  183. {Opt_stack, "cluster_stack=%s"},
  184. {Opt_user_xattr, "user_xattr"},
  185. {Opt_nouser_xattr, "nouser_xattr"},
  186. {Opt_inode64, "inode64"},
  187. {Opt_acl, "acl"},
  188. {Opt_noacl, "noacl"},
  189. {Opt_usrquota, "usrquota"},
  190. {Opt_grpquota, "grpquota"},
  191. {Opt_resv_level, "resv_level=%u"},
  192. {Opt_dir_resv_level, "dir_resv_level=%u"},
  193. {Opt_err, NULL}
  194. };
  195. #ifdef CONFIG_DEBUG_FS
  196. static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
  197. {
  198. struct ocfs2_cluster_connection *cconn = osb->cconn;
  199. struct ocfs2_recovery_map *rm = osb->recovery_map;
  200. struct ocfs2_orphan_scan *os = &osb->osb_orphan_scan;
  201. int i, out = 0;
  202. out += snprintf(buf + out, len - out,
  203. "%10s => Id: %-s Uuid: %-s Gen: 0x%X Label: %-s\n",
  204. "Device", osb->dev_str, osb->uuid_str,
  205. osb->fs_generation, osb->vol_label);
  206. out += snprintf(buf + out, len - out,
  207. "%10s => State: %d Flags: 0x%lX\n", "Volume",
  208. atomic_read(&osb->vol_state), osb->osb_flags);
  209. out += snprintf(buf + out, len - out,
  210. "%10s => Block: %lu Cluster: %d\n", "Sizes",
  211. osb->sb->s_blocksize, osb->s_clustersize);
  212. out += snprintf(buf + out, len - out,
  213. "%10s => Compat: 0x%X Incompat: 0x%X "
  214. "ROcompat: 0x%X\n",
  215. "Features", osb->s_feature_compat,
  216. osb->s_feature_incompat, osb->s_feature_ro_compat);
  217. out += snprintf(buf + out, len - out,
  218. "%10s => Opts: 0x%lX AtimeQuanta: %u\n", "Mount",
  219. osb->s_mount_opt, osb->s_atime_quantum);
  220. if (cconn) {
  221. out += snprintf(buf + out, len - out,
  222. "%10s => Stack: %s Name: %*s "
  223. "Version: %d.%d\n", "Cluster",
  224. (*osb->osb_cluster_stack == '\0' ?
  225. "o2cb" : osb->osb_cluster_stack),
  226. cconn->cc_namelen, cconn->cc_name,
  227. cconn->cc_version.pv_major,
  228. cconn->cc_version.pv_minor);
  229. }
  230. spin_lock(&osb->dc_task_lock);
  231. out += snprintf(buf + out, len - out,
  232. "%10s => Pid: %d Count: %lu WakeSeq: %lu "
  233. "WorkSeq: %lu\n", "DownCnvt",
  234. (osb->dc_task ? task_pid_nr(osb->dc_task) : -1),
  235. osb->blocked_lock_count, osb->dc_wake_sequence,
  236. osb->dc_work_sequence);
  237. spin_unlock(&osb->dc_task_lock);
  238. spin_lock(&osb->osb_lock);
  239. out += snprintf(buf + out, len - out, "%10s => Pid: %d Nodes:",
  240. "Recovery",
  241. (osb->recovery_thread_task ?
  242. task_pid_nr(osb->recovery_thread_task) : -1));
  243. if (rm->rm_used == 0)
  244. out += snprintf(buf + out, len - out, " None\n");
  245. else {
  246. for (i = 0; i < rm->rm_used; i++)
  247. out += snprintf(buf + out, len - out, " %d",
  248. rm->rm_entries[i]);
  249. out += snprintf(buf + out, len - out, "\n");
  250. }
  251. spin_unlock(&osb->osb_lock);
  252. out += snprintf(buf + out, len - out,
  253. "%10s => Pid: %d Interval: %lu Needs: %d\n", "Commit",
  254. (osb->commit_task ? task_pid_nr(osb->commit_task) : -1),
  255. osb->osb_commit_interval,
  256. atomic_read(&osb->needs_checkpoint));
  257. out += snprintf(buf + out, len - out,
  258. "%10s => State: %d TxnId: %lu NumTxns: %d\n",
  259. "Journal", osb->journal->j_state,
  260. osb->journal->j_trans_id,
  261. atomic_read(&osb->journal->j_num_trans));
  262. out += snprintf(buf + out, len - out,
  263. "%10s => GlobalAllocs: %d LocalAllocs: %d "
  264. "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
  265. "Stats",
  266. atomic_read(&osb->alloc_stats.bitmap_data),
  267. atomic_read(&osb->alloc_stats.local_data),
  268. atomic_read(&osb->alloc_stats.bg_allocs),
  269. atomic_read(&osb->alloc_stats.moves),
  270. atomic_read(&osb->alloc_stats.bg_extends));
  271. out += snprintf(buf + out, len - out,
  272. "%10s => State: %u Descriptor: %llu Size: %u bits "
  273. "Default: %u bits\n",
  274. "LocalAlloc", osb->local_alloc_state,
  275. (unsigned long long)osb->la_last_gd,
  276. osb->local_alloc_bits, osb->local_alloc_default_bits);
  277. spin_lock(&osb->osb_lock);
  278. out += snprintf(buf + out, len - out,
  279. "%10s => InodeSlot: %d StolenInodes: %d, "
  280. "MetaSlot: %d StolenMeta: %d\n", "Steal",
  281. osb->s_inode_steal_slot,
  282. atomic_read(&osb->s_num_inodes_stolen),
  283. osb->s_meta_steal_slot,
  284. atomic_read(&osb->s_num_meta_stolen));
  285. spin_unlock(&osb->osb_lock);
  286. out += snprintf(buf + out, len - out, "OrphanScan => ");
  287. out += snprintf(buf + out, len - out, "Local: %u Global: %u ",
  288. os->os_count, os->os_seqno);
  289. out += snprintf(buf + out, len - out, " Last Scan: ");
  290. if (atomic_read(&os->os_state) == ORPHAN_SCAN_INACTIVE)
  291. out += snprintf(buf + out, len - out, "Disabled\n");
  292. else
  293. out += snprintf(buf + out, len - out, "%lu seconds ago\n",
  294. (get_seconds() - os->os_scantime.tv_sec));
  295. out += snprintf(buf + out, len - out, "%10s => %3s %10s\n",
  296. "Slots", "Num", "RecoGen");
  297. for (i = 0; i < osb->max_slots; ++i) {
  298. out += snprintf(buf + out, len - out,
  299. "%10s %c %3d %10d\n",
  300. " ",
  301. (i == osb->slot_num ? '*' : ' '),
  302. i, osb->slot_recovery_generations[i]);
  303. }
  304. return out;
  305. }
  306. static int ocfs2_osb_debug_open(struct inode *inode, struct file *file)
  307. {
  308. struct ocfs2_super *osb = inode->i_private;
  309. char *buf = NULL;
  310. buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
  311. if (!buf)
  312. goto bail;
  313. i_size_write(inode, ocfs2_osb_dump(osb, buf, PAGE_SIZE));
  314. file->private_data = buf;
  315. return 0;
  316. bail:
  317. return -ENOMEM;
  318. }
  319. static int ocfs2_debug_release(struct inode *inode, struct file *file)
  320. {
  321. kfree(file->private_data);
  322. return 0;
  323. }
  324. static ssize_t ocfs2_debug_read(struct file *file, char __user *buf,
  325. size_t nbytes, loff_t *ppos)
  326. {
  327. return simple_read_from_buffer(buf, nbytes, ppos, file->private_data,
  328. i_size_read(file->f_mapping->host));
  329. }
  330. #else
  331. static int ocfs2_osb_debug_open(struct inode *inode, struct file *file)
  332. {
  333. return 0;
  334. }
  335. static int ocfs2_debug_release(struct inode *inode, struct file *file)
  336. {
  337. return 0;
  338. }
  339. static ssize_t ocfs2_debug_read(struct file *file, char __user *buf,
  340. size_t nbytes, loff_t *ppos)
  341. {
  342. return 0;
  343. }
  344. #endif /* CONFIG_DEBUG_FS */
  345. static const struct file_operations ocfs2_osb_debug_fops = {
  346. .open = ocfs2_osb_debug_open,
  347. .release = ocfs2_debug_release,
  348. .read = ocfs2_debug_read,
  349. .llseek = generic_file_llseek,
  350. };
  351. static int ocfs2_sync_fs(struct super_block *sb, int wait)
  352. {
  353. int status;
  354. tid_t target;
  355. struct ocfs2_super *osb = OCFS2_SB(sb);
  356. if (ocfs2_is_hard_readonly(osb))
  357. return -EROFS;
  358. if (wait) {
  359. status = ocfs2_flush_truncate_log(osb);
  360. if (status < 0)
  361. mlog_errno(status);
  362. } else {
  363. ocfs2_schedule_truncate_log_flush(osb, 0);
  364. }
  365. if (jbd2_journal_start_commit(OCFS2_SB(sb)->journal->j_journal,
  366. &target)) {
  367. if (wait)
  368. jbd2_log_wait_commit(OCFS2_SB(sb)->journal->j_journal,
  369. target);
  370. }
  371. return 0;
  372. }
  373. static int ocfs2_need_system_inode(struct ocfs2_super *osb, int ino)
  374. {
  375. if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_RO_COMPAT_USRQUOTA)
  376. && (ino == USER_QUOTA_SYSTEM_INODE
  377. || ino == LOCAL_USER_QUOTA_SYSTEM_INODE))
  378. return 0;
  379. if (!OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)
  380. && (ino == GROUP_QUOTA_SYSTEM_INODE
  381. || ino == LOCAL_GROUP_QUOTA_SYSTEM_INODE))
  382. return 0;
  383. return 1;
  384. }
  385. static int ocfs2_init_global_system_inodes(struct ocfs2_super *osb)
  386. {
  387. struct inode *new = NULL;
  388. int status = 0;
  389. int i;
  390. mlog_entry_void();
  391. new = ocfs2_iget(osb, osb->root_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
  392. if (IS_ERR(new)) {
  393. status = PTR_ERR(new);
  394. mlog_errno(status);
  395. goto bail;
  396. }
  397. osb->root_inode = new;
  398. new = ocfs2_iget(osb, osb->system_dir_blkno, OCFS2_FI_FLAG_SYSFILE, 0);
  399. if (IS_ERR(new)) {
  400. status = PTR_ERR(new);
  401. mlog_errno(status);
  402. goto bail;
  403. }
  404. osb->sys_root_inode = new;
  405. for (i = OCFS2_FIRST_ONLINE_SYSTEM_INODE;
  406. i <= OCFS2_LAST_GLOBAL_SYSTEM_INODE; i++) {
  407. if (!ocfs2_need_system_inode(osb, i))
  408. continue;
  409. new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);
  410. if (!new) {
  411. ocfs2_release_system_inodes(osb);
  412. status = -EINVAL;
  413. mlog_errno(status);
  414. /* FIXME: Should ERROR_RO_FS */
  415. mlog(ML_ERROR, "Unable to load system inode %d, "
  416. "possibly corrupt fs?", i);
  417. goto bail;
  418. }
  419. // the array now has one ref, so drop this one
  420. iput(new);
  421. }
  422. bail:
  423. mlog_exit(status);
  424. return status;
  425. }
  426. static int ocfs2_init_local_system_inodes(struct ocfs2_super *osb)
  427. {
  428. struct inode *new = NULL;
  429. int status = 0;
  430. int i;
  431. mlog_entry_void();
  432. for (i = OCFS2_LAST_GLOBAL_SYSTEM_INODE + 1;
  433. i < NUM_SYSTEM_INODES;
  434. i++) {
  435. if (!ocfs2_need_system_inode(osb, i))
  436. continue;
  437. new = ocfs2_get_system_file_inode(osb, i, osb->slot_num);
  438. if (!new) {
  439. ocfs2_release_system_inodes(osb);
  440. status = -EINVAL;
  441. mlog(ML_ERROR, "status=%d, sysfile=%d, slot=%d\n",
  442. status, i, osb->slot_num);
  443. goto bail;
  444. }
  445. /* the array now has one ref, so drop this one */
  446. iput(new);
  447. }
  448. bail:
  449. mlog_exit(status);
  450. return status;
  451. }
  452. static void ocfs2_release_system_inodes(struct ocfs2_super *osb)
  453. {
  454. int i;
  455. struct inode *inode;
  456. mlog_entry_void();
  457. for (i = 0; i < NUM_SYSTEM_INODES; i++) {
  458. inode = osb->system_inodes[i];
  459. if (inode) {
  460. iput(inode);
  461. osb->system_inodes[i] = NULL;
  462. }
  463. }
  464. inode = osb->sys_root_inode;
  465. if (inode) {
  466. iput(inode);
  467. osb->sys_root_inode = NULL;
  468. }
  469. inode = osb->root_inode;
  470. if (inode) {
  471. iput(inode);
  472. osb->root_inode = NULL;
  473. }
  474. mlog_exit(0);
  475. }
  476. /* We're allocating fs objects, use GFP_NOFS */
  477. static struct inode *ocfs2_alloc_inode(struct super_block *sb)
  478. {
  479. struct ocfs2_inode_info *oi;
  480. oi = kmem_cache_alloc(ocfs2_inode_cachep, GFP_NOFS);
  481. if (!oi)
  482. return NULL;
  483. jbd2_journal_init_jbd_inode(&oi->ip_jinode, &oi->vfs_inode);
  484. return &oi->vfs_inode;
  485. }
  486. static void ocfs2_destroy_inode(struct inode *inode)
  487. {
  488. kmem_cache_free(ocfs2_inode_cachep, OCFS2_I(inode));
  489. }
  490. static unsigned long long ocfs2_max_file_offset(unsigned int bbits,
  491. unsigned int cbits)
  492. {
  493. unsigned int bytes = 1 << cbits;
  494. unsigned int trim = bytes;
  495. unsigned int bitshift = 32;
  496. /*
  497. * i_size and all block offsets in ocfs2 are always 64 bits
  498. * wide. i_clusters is 32 bits, in cluster-sized units. So on
  499. * 64 bit platforms, cluster size will be the limiting factor.
  500. */
  501. #if BITS_PER_LONG == 32
  502. # if defined(CONFIG_LBDAF)
  503. BUILD_BUG_ON(sizeof(sector_t) != 8);
  504. /*
  505. * We might be limited by page cache size.
  506. */
  507. if (bytes > PAGE_CACHE_SIZE) {
  508. bytes = PAGE_CACHE_SIZE;
  509. trim = 1;
  510. /*
  511. * Shift by 31 here so that we don't get larger than
  512. * MAX_LFS_FILESIZE
  513. */
  514. bitshift = 31;
  515. }
  516. # else
  517. /*
  518. * We are limited by the size of sector_t. Use block size, as
  519. * that's what we expose to the VFS.
  520. */
  521. bytes = 1 << bbits;
  522. trim = 1;
  523. bitshift = 31;
  524. # endif
  525. #endif
  526. /*
  527. * Trim by a whole cluster when we can actually approach the
  528. * on-disk limits. Otherwise we can overflow i_clusters when
  529. * an extent start is at the max offset.
  530. */
  531. return (((unsigned long long)bytes) << bitshift) - trim;
  532. }
  533. static int ocfs2_remount(struct super_block *sb, int *flags, char *data)
  534. {
  535. int incompat_features;
  536. int ret = 0;
  537. struct mount_options parsed_options;
  538. struct ocfs2_super *osb = OCFS2_SB(sb);
  539. lock_kernel();
  540. if (!ocfs2_parse_options(sb, data, &parsed_options, 1) ||
  541. !ocfs2_check_set_options(sb, &parsed_options)) {
  542. ret = -EINVAL;
  543. goto out;
  544. }
  545. if ((osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) !=
  546. (parsed_options.mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
  547. ret = -EINVAL;
  548. mlog(ML_ERROR, "Cannot change heartbeat mode on remount\n");
  549. goto out;
  550. }
  551. if ((osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK) !=
  552. (parsed_options.mount_opt & OCFS2_MOUNT_DATA_WRITEBACK)) {
  553. ret = -EINVAL;
  554. mlog(ML_ERROR, "Cannot change data mode on remount\n");
  555. goto out;
  556. }
  557. /* Probably don't want this on remount; it might
  558. * mess with other nodes */
  559. if (!(osb->s_mount_opt & OCFS2_MOUNT_INODE64) &&
  560. (parsed_options.mount_opt & OCFS2_MOUNT_INODE64)) {
  561. ret = -EINVAL;
  562. mlog(ML_ERROR, "Cannot enable inode64 on remount\n");
  563. goto out;
  564. }
  565. /* We're going to/from readonly mode. */
  566. if ((*flags & MS_RDONLY) != (sb->s_flags & MS_RDONLY)) {
  567. /* Disable quota accounting before remounting RO */
  568. if (*flags & MS_RDONLY) {
  569. ret = ocfs2_susp_quotas(osb, 0);
  570. if (ret < 0)
  571. goto out;
  572. }
  573. /* Lock here so the check of HARD_RO and the potential
  574. * setting of SOFT_RO is atomic. */
  575. spin_lock(&osb->osb_lock);
  576. if (osb->osb_flags & OCFS2_OSB_HARD_RO) {
  577. mlog(ML_ERROR, "Remount on readonly device is forbidden.\n");
  578. ret = -EROFS;
  579. goto unlock_osb;
  580. }
  581. if (*flags & MS_RDONLY) {
  582. mlog(0, "Going to ro mode.\n");
  583. sb->s_flags |= MS_RDONLY;
  584. osb->osb_flags |= OCFS2_OSB_SOFT_RO;
  585. } else {
  586. mlog(0, "Making ro filesystem writeable.\n");
  587. if (osb->osb_flags & OCFS2_OSB_ERROR_FS) {
  588. mlog(ML_ERROR, "Cannot remount RDWR "
  589. "filesystem due to previous errors.\n");
  590. ret = -EROFS;
  591. goto unlock_osb;
  592. }
  593. incompat_features = OCFS2_HAS_RO_COMPAT_FEATURE(sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP);
  594. if (incompat_features) {
  595. mlog(ML_ERROR, "Cannot remount RDWR because "
  596. "of unsupported optional features "
  597. "(%x).\n", incompat_features);
  598. ret = -EINVAL;
  599. goto unlock_osb;
  600. }
  601. sb->s_flags &= ~MS_RDONLY;
  602. osb->osb_flags &= ~OCFS2_OSB_SOFT_RO;
  603. }
  604. unlock_osb:
  605. spin_unlock(&osb->osb_lock);
  606. /* Enable quota accounting after remounting RW */
  607. if (!ret && !(*flags & MS_RDONLY)) {
  608. if (sb_any_quota_suspended(sb))
  609. ret = ocfs2_susp_quotas(osb, 1);
  610. else
  611. ret = ocfs2_enable_quotas(osb);
  612. if (ret < 0) {
  613. /* Return back changes... */
  614. spin_lock(&osb->osb_lock);
  615. sb->s_flags |= MS_RDONLY;
  616. osb->osb_flags |= OCFS2_OSB_SOFT_RO;
  617. spin_unlock(&osb->osb_lock);
  618. goto out;
  619. }
  620. }
  621. }
  622. if (!ret) {
  623. /* Only save off the new mount options in case of a successful
  624. * remount. */
  625. osb->s_mount_opt = parsed_options.mount_opt;
  626. osb->s_atime_quantum = parsed_options.atime_quantum;
  627. osb->preferred_slot = parsed_options.slot;
  628. if (parsed_options.commit_interval)
  629. osb->osb_commit_interval = parsed_options.commit_interval;
  630. if (!ocfs2_is_hard_readonly(osb))
  631. ocfs2_set_journal_params(osb);
  632. sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
  633. ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ?
  634. MS_POSIXACL : 0);
  635. }
  636. out:
  637. unlock_kernel();
  638. return ret;
  639. }
  640. static int ocfs2_sb_probe(struct super_block *sb,
  641. struct buffer_head **bh,
  642. int *sector_size,
  643. struct ocfs2_blockcheck_stats *stats)
  644. {
  645. int status, tmpstat;
  646. struct ocfs1_vol_disk_hdr *hdr;
  647. struct ocfs2_dinode *di;
  648. int blksize;
  649. *bh = NULL;
  650. /* may be > 512 */
  651. *sector_size = bdev_logical_block_size(sb->s_bdev);
  652. if (*sector_size > OCFS2_MAX_BLOCKSIZE) {
  653. mlog(ML_ERROR, "Hardware sector size too large: %d (max=%d)\n",
  654. *sector_size, OCFS2_MAX_BLOCKSIZE);
  655. status = -EINVAL;
  656. goto bail;
  657. }
  658. /* Can this really happen? */
  659. if (*sector_size < OCFS2_MIN_BLOCKSIZE)
  660. *sector_size = OCFS2_MIN_BLOCKSIZE;
  661. /* check block zero for old format */
  662. status = ocfs2_get_sector(sb, bh, 0, *sector_size);
  663. if (status < 0) {
  664. mlog_errno(status);
  665. goto bail;
  666. }
  667. hdr = (struct ocfs1_vol_disk_hdr *) (*bh)->b_data;
  668. if (hdr->major_version == OCFS1_MAJOR_VERSION) {
  669. mlog(ML_ERROR, "incompatible version: %u.%u\n",
  670. hdr->major_version, hdr->minor_version);
  671. status = -EINVAL;
  672. }
  673. if (memcmp(hdr->signature, OCFS1_VOLUME_SIGNATURE,
  674. strlen(OCFS1_VOLUME_SIGNATURE)) == 0) {
  675. mlog(ML_ERROR, "incompatible volume signature: %8s\n",
  676. hdr->signature);
  677. status = -EINVAL;
  678. }
  679. brelse(*bh);
  680. *bh = NULL;
  681. if (status < 0) {
  682. mlog(ML_ERROR, "This is an ocfs v1 filesystem which must be "
  683. "upgraded before mounting with ocfs v2\n");
  684. goto bail;
  685. }
  686. /*
  687. * Now check at magic offset for 512, 1024, 2048, 4096
  688. * blocksizes. 4096 is the maximum blocksize because it is
  689. * the minimum clustersize.
  690. */
  691. status = -EINVAL;
  692. for (blksize = *sector_size;
  693. blksize <= OCFS2_MAX_BLOCKSIZE;
  694. blksize <<= 1) {
  695. tmpstat = ocfs2_get_sector(sb, bh,
  696. OCFS2_SUPER_BLOCK_BLKNO,
  697. blksize);
  698. if (tmpstat < 0) {
  699. status = tmpstat;
  700. mlog_errno(status);
  701. break;
  702. }
  703. di = (struct ocfs2_dinode *) (*bh)->b_data;
  704. memset(stats, 0, sizeof(struct ocfs2_blockcheck_stats));
  705. spin_lock_init(&stats->b_lock);
  706. tmpstat = ocfs2_verify_volume(di, *bh, blksize, stats);
  707. if (tmpstat < 0) {
  708. brelse(*bh);
  709. *bh = NULL;
  710. }
  711. if (tmpstat != -EAGAIN) {
  712. status = tmpstat;
  713. break;
  714. }
  715. }
  716. bail:
  717. return status;
  718. }
  719. static int ocfs2_verify_heartbeat(struct ocfs2_super *osb)
  720. {
  721. if (ocfs2_mount_local(osb)) {
  722. if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
  723. mlog(ML_ERROR, "Cannot heartbeat on a locally "
  724. "mounted device.\n");
  725. return -EINVAL;
  726. }
  727. }
  728. if (ocfs2_userspace_stack(osb)) {
  729. if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
  730. mlog(ML_ERROR, "Userspace stack expected, but "
  731. "o2cb heartbeat arguments passed to mount\n");
  732. return -EINVAL;
  733. }
  734. }
  735. if (!(osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL)) {
  736. if (!ocfs2_mount_local(osb) && !ocfs2_is_hard_readonly(osb) &&
  737. !ocfs2_userspace_stack(osb)) {
  738. mlog(ML_ERROR, "Heartbeat has to be started to mount "
  739. "a read-write clustered device.\n");
  740. return -EINVAL;
  741. }
  742. }
  743. return 0;
  744. }
  745. /*
  746. * If we're using a userspace stack, mount should have passed
  747. * a name that matches the disk. If not, mount should not
  748. * have passed a stack.
  749. */
  750. static int ocfs2_verify_userspace_stack(struct ocfs2_super *osb,
  751. struct mount_options *mopt)
  752. {
  753. if (!ocfs2_userspace_stack(osb) && mopt->cluster_stack[0]) {
  754. mlog(ML_ERROR,
  755. "cluster stack passed to mount, but this filesystem "
  756. "does not support it\n");
  757. return -EINVAL;
  758. }
  759. if (ocfs2_userspace_stack(osb) &&
  760. strncmp(osb->osb_cluster_stack, mopt->cluster_stack,
  761. OCFS2_STACK_LABEL_LEN)) {
  762. mlog(ML_ERROR,
  763. "cluster stack passed to mount (\"%s\") does not "
  764. "match the filesystem (\"%s\")\n",
  765. mopt->cluster_stack,
  766. osb->osb_cluster_stack);
  767. return -EINVAL;
  768. }
  769. return 0;
  770. }
  771. static int ocfs2_susp_quotas(struct ocfs2_super *osb, int unsuspend)
  772. {
  773. int type;
  774. struct super_block *sb = osb->sb;
  775. unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
  776. OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
  777. int status = 0;
  778. for (type = 0; type < MAXQUOTAS; type++) {
  779. if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
  780. continue;
  781. if (unsuspend)
  782. status = dquot_resume(sb, type);
  783. else {
  784. struct ocfs2_mem_dqinfo *oinfo;
  785. /* Cancel periodic syncing before suspending */
  786. oinfo = sb_dqinfo(sb, type)->dqi_priv;
  787. cancel_delayed_work_sync(&oinfo->dqi_sync_work);
  788. status = dquot_suspend(sb, type);
  789. }
  790. if (status < 0)
  791. break;
  792. }
  793. if (status < 0)
  794. mlog(ML_ERROR, "Failed to suspend/unsuspend quotas on "
  795. "remount (error = %d).\n", status);
  796. return status;
  797. }
  798. static int ocfs2_enable_quotas(struct ocfs2_super *osb)
  799. {
  800. struct inode *inode[MAXQUOTAS] = { NULL, NULL };
  801. struct super_block *sb = osb->sb;
  802. unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
  803. OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
  804. unsigned int ino[MAXQUOTAS] = { LOCAL_USER_QUOTA_SYSTEM_INODE,
  805. LOCAL_GROUP_QUOTA_SYSTEM_INODE };
  806. int status;
  807. int type;
  808. sb_dqopt(sb)->flags |= DQUOT_QUOTA_SYS_FILE | DQUOT_NEGATIVE_USAGE;
  809. for (type = 0; type < MAXQUOTAS; type++) {
  810. if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
  811. continue;
  812. inode[type] = ocfs2_get_system_file_inode(osb, ino[type],
  813. osb->slot_num);
  814. if (!inode[type]) {
  815. status = -ENOENT;
  816. goto out_quota_off;
  817. }
  818. status = vfs_quota_enable(inode[type], type, QFMT_OCFS2,
  819. DQUOT_USAGE_ENABLED);
  820. if (status < 0)
  821. goto out_quota_off;
  822. }
  823. for (type = 0; type < MAXQUOTAS; type++)
  824. iput(inode[type]);
  825. return 0;
  826. out_quota_off:
  827. ocfs2_disable_quotas(osb);
  828. for (type = 0; type < MAXQUOTAS; type++)
  829. iput(inode[type]);
  830. mlog_errno(status);
  831. return status;
  832. }
  833. static void ocfs2_disable_quotas(struct ocfs2_super *osb)
  834. {
  835. int type;
  836. struct inode *inode;
  837. struct super_block *sb = osb->sb;
  838. struct ocfs2_mem_dqinfo *oinfo;
  839. /* We mostly ignore errors in this function because there's not much
  840. * we can do when we see them */
  841. for (type = 0; type < MAXQUOTAS; type++) {
  842. if (!sb_has_quota_loaded(sb, type))
  843. continue;
  844. /* Cancel periodic syncing before we grab dqonoff_mutex */
  845. oinfo = sb_dqinfo(sb, type)->dqi_priv;
  846. cancel_delayed_work_sync(&oinfo->dqi_sync_work);
  847. inode = igrab(sb->s_dquot.files[type]);
  848. /* Turn off quotas. This will remove all dquot structures from
  849. * memory and so they will be automatically synced to global
  850. * quota files */
  851. dquot_disable(sb, type, DQUOT_USAGE_ENABLED |
  852. DQUOT_LIMITS_ENABLED);
  853. if (!inode)
  854. continue;
  855. iput(inode);
  856. }
  857. }
  858. /* Handle quota on quotactl */
  859. static int ocfs2_quota_on(struct super_block *sb, int type, int format_id,
  860. char *path, int remount)
  861. {
  862. unsigned int feature[MAXQUOTAS] = { OCFS2_FEATURE_RO_COMPAT_USRQUOTA,
  863. OCFS2_FEATURE_RO_COMPAT_GRPQUOTA};
  864. if (!OCFS2_HAS_RO_COMPAT_FEATURE(sb, feature[type]))
  865. return -EINVAL;
  866. if (remount)
  867. return 0; /* Just ignore it has been handled in
  868. * ocfs2_remount() */
  869. return vfs_quota_enable(sb_dqopt(sb)->files[type], type,
  870. format_id, DQUOT_LIMITS_ENABLED);
  871. }
  872. /* Handle quota off quotactl */
  873. static int ocfs2_quota_off(struct super_block *sb, int type, int remount)
  874. {
  875. if (remount)
  876. return 0; /* Ignore now and handle later in
  877. * ocfs2_remount() */
  878. return dquot_disable(sb, type, DQUOT_LIMITS_ENABLED);
  879. }
  880. static const struct quotactl_ops ocfs2_quotactl_ops = {
  881. .quota_on = ocfs2_quota_on,
  882. .quota_off = ocfs2_quota_off,
  883. .quota_sync = vfs_quota_sync,
  884. .get_info = vfs_get_dqinfo,
  885. .set_info = vfs_set_dqinfo,
  886. .get_dqblk = vfs_get_dqblk,
  887. .set_dqblk = vfs_set_dqblk,
  888. };
  889. static int ocfs2_fill_super(struct super_block *sb, void *data, int silent)
  890. {
  891. struct dentry *root;
  892. int status, sector_size;
  893. struct mount_options parsed_options;
  894. struct inode *inode = NULL;
  895. struct ocfs2_super *osb = NULL;
  896. struct buffer_head *bh = NULL;
  897. char nodestr[8];
  898. struct ocfs2_blockcheck_stats stats;
  899. mlog_entry("%p, %p, %i", sb, data, silent);
  900. if (!ocfs2_parse_options(sb, data, &parsed_options, 0)) {
  901. status = -EINVAL;
  902. goto read_super_error;
  903. }
  904. /* probe for superblock */
  905. status = ocfs2_sb_probe(sb, &bh, &sector_size, &stats);
  906. if (status < 0) {
  907. mlog(ML_ERROR, "superblock probe failed!\n");
  908. goto read_super_error;
  909. }
  910. status = ocfs2_initialize_super(sb, bh, sector_size, &stats);
  911. osb = OCFS2_SB(sb);
  912. if (status < 0) {
  913. mlog_errno(status);
  914. goto read_super_error;
  915. }
  916. brelse(bh);
  917. bh = NULL;
  918. if (!ocfs2_check_set_options(sb, &parsed_options)) {
  919. status = -EINVAL;
  920. goto read_super_error;
  921. }
  922. osb->s_mount_opt = parsed_options.mount_opt;
  923. osb->s_atime_quantum = parsed_options.atime_quantum;
  924. osb->preferred_slot = parsed_options.slot;
  925. osb->osb_commit_interval = parsed_options.commit_interval;
  926. ocfs2_la_set_sizes(osb, parsed_options.localalloc_opt);
  927. osb->osb_resv_level = parsed_options.resv_level;
  928. osb->osb_dir_resv_level = parsed_options.resv_level;
  929. if (parsed_options.dir_resv_level == -1)
  930. osb->osb_dir_resv_level = parsed_options.resv_level;
  931. else
  932. osb->osb_dir_resv_level = parsed_options.dir_resv_level;
  933. status = ocfs2_verify_userspace_stack(osb, &parsed_options);
  934. if (status)
  935. goto read_super_error;
  936. sb->s_magic = OCFS2_SUPER_MAGIC;
  937. sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
  938. ((osb->s_mount_opt & OCFS2_MOUNT_POSIX_ACL) ? MS_POSIXACL : 0);
  939. /* Hard readonly mode only if: bdev_read_only, MS_RDONLY,
  940. * heartbeat=none */
  941. if (bdev_read_only(sb->s_bdev)) {
  942. if (!(sb->s_flags & MS_RDONLY)) {
  943. status = -EACCES;
  944. mlog(ML_ERROR, "Readonly device detected but readonly "
  945. "mount was not specified.\n");
  946. goto read_super_error;
  947. }
  948. /* You should not be able to start a local heartbeat
  949. * on a readonly device. */
  950. if (osb->s_mount_opt & OCFS2_MOUNT_HB_LOCAL) {
  951. status = -EROFS;
  952. mlog(ML_ERROR, "Local heartbeat specified on readonly "
  953. "device.\n");
  954. goto read_super_error;
  955. }
  956. status = ocfs2_check_journals_nolocks(osb);
  957. if (status < 0) {
  958. if (status == -EROFS)
  959. mlog(ML_ERROR, "Recovery required on readonly "
  960. "file system, but write access is "
  961. "unavailable.\n");
  962. else
  963. mlog_errno(status);
  964. goto read_super_error;
  965. }
  966. ocfs2_set_ro_flag(osb, 1);
  967. printk(KERN_NOTICE "Readonly device detected. No cluster "
  968. "services will be utilized for this mount. Recovery "
  969. "will be skipped.\n");
  970. }
  971. if (!ocfs2_is_hard_readonly(osb)) {
  972. if (sb->s_flags & MS_RDONLY)
  973. ocfs2_set_ro_flag(osb, 0);
  974. }
  975. status = ocfs2_verify_heartbeat(osb);
  976. if (status < 0) {
  977. mlog_errno(status);
  978. goto read_super_error;
  979. }
  980. osb->osb_debug_root = debugfs_create_dir(osb->uuid_str,
  981. ocfs2_debugfs_root);
  982. if (!osb->osb_debug_root) {
  983. status = -EINVAL;
  984. mlog(ML_ERROR, "Unable to create per-mount debugfs root.\n");
  985. goto read_super_error;
  986. }
  987. osb->osb_ctxt = debugfs_create_file("fs_state", S_IFREG|S_IRUSR,
  988. osb->osb_debug_root,
  989. osb,
  990. &ocfs2_osb_debug_fops);
  991. if (!osb->osb_ctxt) {
  992. status = -EINVAL;
  993. mlog_errno(status);
  994. goto read_super_error;
  995. }
  996. if (ocfs2_meta_ecc(osb)) {
  997. status = ocfs2_blockcheck_stats_debugfs_install(
  998. &osb->osb_ecc_stats,
  999. osb->osb_debug_root);
  1000. if (status) {
  1001. mlog(ML_ERROR,
  1002. "Unable to create blockcheck statistics "
  1003. "files\n");
  1004. goto read_super_error;
  1005. }
  1006. }
  1007. status = ocfs2_mount_volume(sb);
  1008. if (osb->root_inode)
  1009. inode = igrab(osb->root_inode);
  1010. if (status < 0)
  1011. goto read_super_error;
  1012. if (!inode) {
  1013. status = -EIO;
  1014. mlog_errno(status);
  1015. goto read_super_error;
  1016. }
  1017. root = d_alloc_root(inode);
  1018. if (!root) {
  1019. status = -ENOMEM;
  1020. mlog_errno(status);
  1021. goto read_super_error;
  1022. }
  1023. sb->s_root = root;
  1024. ocfs2_complete_mount_recovery(osb);
  1025. if (ocfs2_mount_local(osb))
  1026. snprintf(nodestr, sizeof(nodestr), "local");
  1027. else
  1028. snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
  1029. printk(KERN_INFO "ocfs2: Mounting device (%s) on (node %s, slot %d) "
  1030. "with %s data mode.\n",
  1031. osb->dev_str, nodestr, osb->slot_num,
  1032. osb->s_mount_opt & OCFS2_MOUNT_DATA_WRITEBACK ? "writeback" :
  1033. "ordered");
  1034. atomic_set(&osb->vol_state, VOLUME_MOUNTED);
  1035. wake_up(&osb->osb_mount_event);
  1036. /* Now we can initialize quotas because we can afford to wait
  1037. * for cluster locks recovery now. That also means that truncation
  1038. * log recovery can happen but that waits for proper quota setup */
  1039. if (!(sb->s_flags & MS_RDONLY)) {
  1040. status = ocfs2_enable_quotas(osb);
  1041. if (status < 0) {
  1042. /* We have to err-out specially here because
  1043. * s_root is already set */
  1044. mlog_errno(status);
  1045. atomic_set(&osb->vol_state, VOLUME_DISABLED);
  1046. wake_up(&osb->osb_mount_event);
  1047. mlog_exit(status);
  1048. return status;
  1049. }
  1050. }
  1051. ocfs2_complete_quota_recovery(osb);
  1052. /* Now we wake up again for processes waiting for quotas */
  1053. atomic_set(&osb->vol_state, VOLUME_MOUNTED_QUOTAS);
  1054. wake_up(&osb->osb_mount_event);
  1055. /* Start this when the mount is almost sure of being successful */
  1056. ocfs2_orphan_scan_start(osb);
  1057. mlog_exit(status);
  1058. return status;
  1059. read_super_error:
  1060. brelse(bh);
  1061. if (inode)
  1062. iput(inode);
  1063. if (osb) {
  1064. atomic_set(&osb->vol_state, VOLUME_DISABLED);
  1065. wake_up(&osb->osb_mount_event);
  1066. ocfs2_dismount_volume(sb, 1);
  1067. }
  1068. mlog_exit(status);
  1069. return status;
  1070. }
  1071. static int ocfs2_get_sb(struct file_system_type *fs_type,
  1072. int flags,
  1073. const char *dev_name,
  1074. void *data,
  1075. struct vfsmount *mnt)
  1076. {
  1077. return get_sb_bdev(fs_type, flags, dev_name, data, ocfs2_fill_super,
  1078. mnt);
  1079. }
  1080. static void ocfs2_kill_sb(struct super_block *sb)
  1081. {
  1082. struct ocfs2_super *osb = OCFS2_SB(sb);
  1083. /* Failed mount? */
  1084. if (!osb || atomic_read(&osb->vol_state) == VOLUME_DISABLED)
  1085. goto out;
  1086. /* Prevent further queueing of inode drop events */
  1087. spin_lock(&dentry_list_lock);
  1088. ocfs2_set_osb_flag(osb, OCFS2_OSB_DROP_DENTRY_LOCK_IMMED);
  1089. spin_unlock(&dentry_list_lock);
  1090. /* Wait for work to finish and/or remove it */
  1091. cancel_work_sync(&osb->dentry_lock_work);
  1092. out:
  1093. kill_block_super(sb);
  1094. }
  1095. static struct file_system_type ocfs2_fs_type = {
  1096. .owner = THIS_MODULE,
  1097. .name = "ocfs2",
  1098. .get_sb = ocfs2_get_sb, /* is this called when we mount
  1099. * the fs? */
  1100. .kill_sb = ocfs2_kill_sb,
  1101. .fs_flags = FS_REQUIRES_DEV|FS_RENAME_DOES_D_MOVE,
  1102. .next = NULL
  1103. };
  1104. static int ocfs2_check_set_options(struct super_block *sb,
  1105. struct mount_options *options)
  1106. {
  1107. if (options->mount_opt & OCFS2_MOUNT_USRQUOTA &&
  1108. !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
  1109. OCFS2_FEATURE_RO_COMPAT_USRQUOTA)) {
  1110. mlog(ML_ERROR, "User quotas were requested, but this "
  1111. "filesystem does not have the feature enabled.\n");
  1112. return 0;
  1113. }
  1114. if (options->mount_opt & OCFS2_MOUNT_GRPQUOTA &&
  1115. !OCFS2_HAS_RO_COMPAT_FEATURE(sb,
  1116. OCFS2_FEATURE_RO_COMPAT_GRPQUOTA)) {
  1117. mlog(ML_ERROR, "Group quotas were requested, but this "
  1118. "filesystem does not have the feature enabled.\n");
  1119. return 0;
  1120. }
  1121. if (options->mount_opt & OCFS2_MOUNT_POSIX_ACL &&
  1122. !OCFS2_HAS_INCOMPAT_FEATURE(sb, OCFS2_FEATURE_INCOMPAT_XATTR)) {
  1123. mlog(ML_ERROR, "ACL support requested but extended attributes "
  1124. "feature is not enabled\n");
  1125. return 0;
  1126. }
  1127. /* No ACL setting specified? Use XATTR feature... */
  1128. if (!(options->mount_opt & (OCFS2_MOUNT_POSIX_ACL |
  1129. OCFS2_MOUNT_NO_POSIX_ACL))) {
  1130. if (OCFS2_HAS_INCOMPAT_FEATURE(sb, OCFS2_FEATURE_INCOMPAT_XATTR))
  1131. options->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
  1132. else
  1133. options->mount_opt |= OCFS2_MOUNT_NO_POSIX_ACL;
  1134. }
  1135. return 1;
  1136. }
  1137. static int ocfs2_parse_options(struct super_block *sb,
  1138. char *options,
  1139. struct mount_options *mopt,
  1140. int is_remount)
  1141. {
  1142. int status;
  1143. char *p;
  1144. mlog_entry("remount: %d, options: \"%s\"\n", is_remount,
  1145. options ? options : "(none)");
  1146. mopt->commit_interval = 0;
  1147. mopt->mount_opt = OCFS2_MOUNT_NOINTR;
  1148. mopt->atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
  1149. mopt->slot = OCFS2_INVALID_SLOT;
  1150. mopt->localalloc_opt = -1;
  1151. mopt->cluster_stack[0] = '\0';
  1152. mopt->resv_level = OCFS2_DEFAULT_RESV_LEVEL;
  1153. mopt->dir_resv_level = -1;
  1154. if (!options) {
  1155. status = 1;
  1156. goto bail;
  1157. }
  1158. while ((p = strsep(&options, ",")) != NULL) {
  1159. int token, option;
  1160. substring_t args[MAX_OPT_ARGS];
  1161. if (!*p)
  1162. continue;
  1163. token = match_token(p, tokens, args);
  1164. switch (token) {
  1165. case Opt_hb_local:
  1166. mopt->mount_opt |= OCFS2_MOUNT_HB_LOCAL;
  1167. break;
  1168. case Opt_hb_none:
  1169. mopt->mount_opt &= ~OCFS2_MOUNT_HB_LOCAL;
  1170. break;
  1171. case Opt_barrier:
  1172. if (match_int(&args[0], &option)) {
  1173. status = 0;
  1174. goto bail;
  1175. }
  1176. if (option)
  1177. mopt->mount_opt |= OCFS2_MOUNT_BARRIER;
  1178. else
  1179. mopt->mount_opt &= ~OCFS2_MOUNT_BARRIER;
  1180. break;
  1181. case Opt_intr:
  1182. mopt->mount_opt &= ~OCFS2_MOUNT_NOINTR;
  1183. break;
  1184. case Opt_nointr:
  1185. mopt->mount_opt |= OCFS2_MOUNT_NOINTR;
  1186. break;
  1187. case Opt_err_panic:
  1188. mopt->mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
  1189. break;
  1190. case Opt_err_ro:
  1191. mopt->mount_opt &= ~OCFS2_MOUNT_ERRORS_PANIC;
  1192. break;
  1193. case Opt_data_ordered:
  1194. mopt->mount_opt &= ~OCFS2_MOUNT_DATA_WRITEBACK;
  1195. break;
  1196. case Opt_data_writeback:
  1197. mopt->mount_opt |= OCFS2_MOUNT_DATA_WRITEBACK;
  1198. break;
  1199. case Opt_user_xattr:
  1200. mopt->mount_opt &= ~OCFS2_MOUNT_NOUSERXATTR;
  1201. break;
  1202. case Opt_nouser_xattr:
  1203. mopt->mount_opt |= OCFS2_MOUNT_NOUSERXATTR;
  1204. break;
  1205. case Opt_atime_quantum:
  1206. if (match_int(&args[0], &option)) {
  1207. status = 0;
  1208. goto bail;
  1209. }
  1210. if (option >= 0)
  1211. mopt->atime_quantum = option;
  1212. break;
  1213. case Opt_slot:
  1214. option = 0;
  1215. if (match_int(&args[0], &option)) {
  1216. status = 0;
  1217. goto bail;
  1218. }
  1219. if (option)
  1220. mopt->slot = (s16)option;
  1221. break;
  1222. case Opt_commit:
  1223. option = 0;
  1224. if (match_int(&args[0], &option)) {
  1225. status = 0;
  1226. goto bail;
  1227. }
  1228. if (option < 0)
  1229. return 0;
  1230. if (option == 0)
  1231. option = JBD2_DEFAULT_MAX_COMMIT_AGE;
  1232. mopt->commit_interval = HZ * option;
  1233. break;
  1234. case Opt_localalloc:
  1235. option = 0;
  1236. if (match_int(&args[0], &option)) {
  1237. status = 0;
  1238. goto bail;
  1239. }
  1240. if (option >= 0)
  1241. mopt->localalloc_opt = option;
  1242. break;
  1243. case Opt_localflocks:
  1244. /*
  1245. * Changing this during remount could race
  1246. * flock() requests, or "unbalance" existing
  1247. * ones (e.g., a lock is taken in one mode but
  1248. * dropped in the other). If users care enough
  1249. * to flip locking modes during remount, we
  1250. * could add a "local" flag to individual
  1251. * flock structures for proper tracking of
  1252. * state.
  1253. */
  1254. if (!is_remount)
  1255. mopt->mount_opt |= OCFS2_MOUNT_LOCALFLOCKS;
  1256. break;
  1257. case Opt_stack:
  1258. /* Check both that the option we were passed
  1259. * is of the right length and that it is a proper
  1260. * string of the right length.
  1261. */
  1262. if (((args[0].to - args[0].from) !=
  1263. OCFS2_STACK_LABEL_LEN) ||
  1264. (strnlen(args[0].from,
  1265. OCFS2_STACK_LABEL_LEN) !=
  1266. OCFS2_STACK_LABEL_LEN)) {
  1267. mlog(ML_ERROR,
  1268. "Invalid cluster_stack option\n");
  1269. status = 0;
  1270. goto bail;
  1271. }
  1272. memcpy(mopt->cluster_stack, args[0].from,
  1273. OCFS2_STACK_LABEL_LEN);
  1274. mopt->cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
  1275. break;
  1276. case Opt_inode64:
  1277. mopt->mount_opt |= OCFS2_MOUNT_INODE64;
  1278. break;
  1279. case Opt_usrquota:
  1280. mopt->mount_opt |= OCFS2_MOUNT_USRQUOTA;
  1281. break;
  1282. case Opt_grpquota:
  1283. mopt->mount_opt |= OCFS2_MOUNT_GRPQUOTA;
  1284. break;
  1285. case Opt_acl:
  1286. mopt->mount_opt |= OCFS2_MOUNT_POSIX_ACL;
  1287. mopt->mount_opt &= ~OCFS2_MOUNT_NO_POSIX_ACL;
  1288. break;
  1289. case Opt_noacl:
  1290. mopt->mount_opt |= OCFS2_MOUNT_NO_POSIX_ACL;
  1291. mopt->mount_opt &= ~OCFS2_MOUNT_POSIX_ACL;
  1292. break;
  1293. case Opt_resv_level:
  1294. if (is_remount)
  1295. break;
  1296. if (match_int(&args[0], &option)) {
  1297. status = 0;
  1298. goto bail;
  1299. }
  1300. if (option >= OCFS2_MIN_RESV_LEVEL &&
  1301. option < OCFS2_MAX_RESV_LEVEL)
  1302. mopt->resv_level = option;
  1303. break;
  1304. case Opt_dir_resv_level:
  1305. if (is_remount)
  1306. break;
  1307. if (match_int(&args[0], &option)) {
  1308. status = 0;
  1309. goto bail;
  1310. }
  1311. if (option >= OCFS2_MIN_RESV_LEVEL &&
  1312. option < OCFS2_MAX_RESV_LEVEL)
  1313. mopt->dir_resv_level = option;
  1314. break;
  1315. default:
  1316. mlog(ML_ERROR,
  1317. "Unrecognized mount option \"%s\" "
  1318. "or missing value\n", p);
  1319. status = 0;
  1320. goto bail;
  1321. }
  1322. }
  1323. status = 1;
  1324. bail:
  1325. mlog_exit(status);
  1326. return status;
  1327. }
  1328. static int ocfs2_show_options(struct seq_file *s, struct vfsmount *mnt)
  1329. {
  1330. struct ocfs2_super *osb = OCFS2_SB(mnt->mnt_sb);
  1331. unsigned long opts = osb->s_mount_opt;
  1332. unsigned int local_alloc_megs;
  1333. if (opts & OCFS2_MOUNT_HB_LOCAL)
  1334. seq_printf(s, ",_netdev,heartbeat=local");
  1335. else
  1336. seq_printf(s, ",heartbeat=none");
  1337. if (opts & OCFS2_MOUNT_NOINTR)
  1338. seq_printf(s, ",nointr");
  1339. if (opts & OCFS2_MOUNT_DATA_WRITEBACK)
  1340. seq_printf(s, ",data=writeback");
  1341. else
  1342. seq_printf(s, ",data=ordered");
  1343. if (opts & OCFS2_MOUNT_BARRIER)
  1344. seq_printf(s, ",barrier=1");
  1345. if (opts & OCFS2_MOUNT_ERRORS_PANIC)
  1346. seq_printf(s, ",errors=panic");
  1347. else
  1348. seq_printf(s, ",errors=remount-ro");
  1349. if (osb->preferred_slot != OCFS2_INVALID_SLOT)
  1350. seq_printf(s, ",preferred_slot=%d", osb->preferred_slot);
  1351. if (osb->s_atime_quantum != OCFS2_DEFAULT_ATIME_QUANTUM)
  1352. seq_printf(s, ",atime_quantum=%u", osb->s_atime_quantum);
  1353. if (osb->osb_commit_interval)
  1354. seq_printf(s, ",commit=%u",
  1355. (unsigned) (osb->osb_commit_interval / HZ));
  1356. local_alloc_megs = osb->local_alloc_bits >> (20 - osb->s_clustersize_bits);
  1357. if (local_alloc_megs != ocfs2_la_default_mb(osb))
  1358. seq_printf(s, ",localalloc=%d", local_alloc_megs);
  1359. if (opts & OCFS2_MOUNT_LOCALFLOCKS)
  1360. seq_printf(s, ",localflocks,");
  1361. if (osb->osb_cluster_stack[0])
  1362. seq_printf(s, ",cluster_stack=%.*s", OCFS2_STACK_LABEL_LEN,
  1363. osb->osb_cluster_stack);
  1364. if (opts & OCFS2_MOUNT_USRQUOTA)
  1365. seq_printf(s, ",usrquota");
  1366. if (opts & OCFS2_MOUNT_GRPQUOTA)
  1367. seq_printf(s, ",grpquota");
  1368. if (opts & OCFS2_MOUNT_NOUSERXATTR)
  1369. seq_printf(s, ",nouser_xattr");
  1370. else
  1371. seq_printf(s, ",user_xattr");
  1372. if (opts & OCFS2_MOUNT_INODE64)
  1373. seq_printf(s, ",inode64");
  1374. if (opts & OCFS2_MOUNT_POSIX_ACL)
  1375. seq_printf(s, ",acl");
  1376. else
  1377. seq_printf(s, ",noacl");
  1378. if (osb->osb_resv_level != OCFS2_DEFAULT_RESV_LEVEL)
  1379. seq_printf(s, ",resv_level=%d", osb->osb_resv_level);
  1380. if (osb->osb_dir_resv_level != osb->osb_resv_level)
  1381. seq_printf(s, ",dir_resv_level=%d", osb->osb_resv_level);
  1382. return 0;
  1383. }
  1384. static int __init ocfs2_init(void)
  1385. {
  1386. int status;
  1387. mlog_entry_void();
  1388. ocfs2_print_version();
  1389. status = init_ocfs2_uptodate_cache();
  1390. if (status < 0) {
  1391. mlog_errno(status);
  1392. goto leave;
  1393. }
  1394. status = ocfs2_initialize_mem_caches();
  1395. if (status < 0) {
  1396. mlog_errno(status);
  1397. goto leave;
  1398. }
  1399. ocfs2_wq = create_singlethread_workqueue("ocfs2_wq");
  1400. if (!ocfs2_wq) {
  1401. status = -ENOMEM;
  1402. goto leave;
  1403. }
  1404. ocfs2_debugfs_root = debugfs_create_dir("ocfs2", NULL);
  1405. if (!ocfs2_debugfs_root) {
  1406. status = -EFAULT;
  1407. mlog(ML_ERROR, "Unable to create ocfs2 debugfs root.\n");
  1408. }
  1409. status = ocfs2_quota_setup();
  1410. if (status)
  1411. goto leave;
  1412. ocfs2_set_locking_protocol();
  1413. status = register_quota_format(&ocfs2_quota_format);
  1414. leave:
  1415. if (status < 0) {
  1416. ocfs2_quota_shutdown();
  1417. ocfs2_free_mem_caches();
  1418. exit_ocfs2_uptodate_cache();
  1419. }
  1420. mlog_exit(status);
  1421. if (status >= 0) {
  1422. return register_filesystem(&ocfs2_fs_type);
  1423. } else
  1424. return -1;
  1425. }
  1426. static void __exit ocfs2_exit(void)
  1427. {
  1428. mlog_entry_void();
  1429. ocfs2_quota_shutdown();
  1430. if (ocfs2_wq) {
  1431. flush_workqueue(ocfs2_wq);
  1432. destroy_workqueue(ocfs2_wq);
  1433. }
  1434. unregister_quota_format(&ocfs2_quota_format);
  1435. debugfs_remove(ocfs2_debugfs_root);
  1436. ocfs2_free_mem_caches();
  1437. unregister_filesystem(&ocfs2_fs_type);
  1438. exit_ocfs2_uptodate_cache();
  1439. mlog_exit_void();
  1440. }
  1441. static void ocfs2_put_super(struct super_block *sb)
  1442. {
  1443. mlog_entry("(0x%p)\n", sb);
  1444. lock_kernel();
  1445. ocfs2_sync_blockdev(sb);
  1446. ocfs2_dismount_volume(sb, 0);
  1447. unlock_kernel();
  1448. mlog_exit_void();
  1449. }
  1450. static int ocfs2_statfs(struct dentry *dentry, struct kstatfs *buf)
  1451. {
  1452. struct ocfs2_super *osb;
  1453. u32 numbits, freebits;
  1454. int status;
  1455. struct ocfs2_dinode *bm_lock;
  1456. struct buffer_head *bh = NULL;
  1457. struct inode *inode = NULL;
  1458. mlog_entry("(%p, %p)\n", dentry->d_sb, buf);
  1459. osb = OCFS2_SB(dentry->d_sb);
  1460. inode = ocfs2_get_system_file_inode(osb,
  1461. GLOBAL_BITMAP_SYSTEM_INODE,
  1462. OCFS2_INVALID_SLOT);
  1463. if (!inode) {
  1464. mlog(ML_ERROR, "failed to get bitmap inode\n");
  1465. status = -EIO;
  1466. goto bail;
  1467. }
  1468. status = ocfs2_inode_lock(inode, &bh, 0);
  1469. if (status < 0) {
  1470. mlog_errno(status);
  1471. goto bail;
  1472. }
  1473. bm_lock = (struct ocfs2_dinode *) bh->b_data;
  1474. numbits = le32_to_cpu(bm_lock->id1.bitmap1.i_total);
  1475. freebits = numbits - le32_to_cpu(bm_lock->id1.bitmap1.i_used);
  1476. buf->f_type = OCFS2_SUPER_MAGIC;
  1477. buf->f_bsize = dentry->d_sb->s_blocksize;
  1478. buf->f_namelen = OCFS2_MAX_FILENAME_LEN;
  1479. buf->f_blocks = ((sector_t) numbits) *
  1480. (osb->s_clustersize >> osb->sb->s_blocksize_bits);
  1481. buf->f_bfree = ((sector_t) freebits) *
  1482. (osb->s_clustersize >> osb->sb->s_blocksize_bits);
  1483. buf->f_bavail = buf->f_bfree;
  1484. buf->f_files = numbits;
  1485. buf->f_ffree = freebits;
  1486. buf->f_fsid.val[0] = crc32_le(0, osb->uuid_str, OCFS2_VOL_UUID_LEN)
  1487. & 0xFFFFFFFFUL;
  1488. buf->f_fsid.val[1] = crc32_le(0, osb->uuid_str + OCFS2_VOL_UUID_LEN,
  1489. OCFS2_VOL_UUID_LEN) & 0xFFFFFFFFUL;
  1490. brelse(bh);
  1491. ocfs2_inode_unlock(inode, 0);
  1492. status = 0;
  1493. bail:
  1494. if (inode)
  1495. iput(inode);
  1496. mlog_exit(status);
  1497. return status;
  1498. }
  1499. static void ocfs2_inode_init_once(void *data)
  1500. {
  1501. struct ocfs2_inode_info *oi = data;
  1502. oi->ip_flags = 0;
  1503. oi->ip_open_count = 0;
  1504. spin_lock_init(&oi->ip_lock);
  1505. ocfs2_extent_map_init(&oi->vfs_inode);
  1506. INIT_LIST_HEAD(&oi->ip_io_markers);
  1507. oi->ip_dir_start_lookup = 0;
  1508. init_rwsem(&oi->ip_alloc_sem);
  1509. init_rwsem(&oi->ip_xattr_sem);
  1510. mutex_init(&oi->ip_io_mutex);
  1511. oi->ip_blkno = 0ULL;
  1512. oi->ip_clusters = 0;
  1513. ocfs2_resv_init_once(&oi->ip_la_data_resv);
  1514. ocfs2_lock_res_init_once(&oi->ip_rw_lockres);
  1515. ocfs2_lock_res_init_once(&oi->ip_inode_lockres);
  1516. ocfs2_lock_res_init_once(&oi->ip_open_lockres);
  1517. ocfs2_metadata_cache_init(INODE_CACHE(&oi->vfs_inode),
  1518. &ocfs2_inode_caching_ops);
  1519. inode_init_once(&oi->vfs_inode);
  1520. }
  1521. static int ocfs2_initialize_mem_caches(void)
  1522. {
  1523. ocfs2_inode_cachep = kmem_cache_create("ocfs2_inode_cache",
  1524. sizeof(struct ocfs2_inode_info),
  1525. 0,
  1526. (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
  1527. SLAB_MEM_SPREAD),
  1528. ocfs2_inode_init_once);
  1529. ocfs2_dquot_cachep = kmem_cache_create("ocfs2_dquot_cache",
  1530. sizeof(struct ocfs2_dquot),
  1531. 0,
  1532. (SLAB_HWCACHE_ALIGN|SLAB_RECLAIM_ACCOUNT|
  1533. SLAB_MEM_SPREAD),
  1534. NULL);
  1535. ocfs2_qf_chunk_cachep = kmem_cache_create("ocfs2_qf_chunk_cache",
  1536. sizeof(struct ocfs2_quota_chunk),
  1537. 0,
  1538. (SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD),
  1539. NULL);
  1540. if (!ocfs2_inode_cachep || !ocfs2_dquot_cachep ||
  1541. !ocfs2_qf_chunk_cachep) {
  1542. if (ocfs2_inode_cachep)
  1543. kmem_cache_destroy(ocfs2_inode_cachep);
  1544. if (ocfs2_dquot_cachep)
  1545. kmem_cache_destroy(ocfs2_dquot_cachep);
  1546. if (ocfs2_qf_chunk_cachep)
  1547. kmem_cache_destroy(ocfs2_qf_chunk_cachep);
  1548. return -ENOMEM;
  1549. }
  1550. return 0;
  1551. }
  1552. static void ocfs2_free_mem_caches(void)
  1553. {
  1554. if (ocfs2_inode_cachep)
  1555. kmem_cache_destroy(ocfs2_inode_cachep);
  1556. ocfs2_inode_cachep = NULL;
  1557. if (ocfs2_dquot_cachep)
  1558. kmem_cache_destroy(ocfs2_dquot_cachep);
  1559. ocfs2_dquot_cachep = NULL;
  1560. if (ocfs2_qf_chunk_cachep)
  1561. kmem_cache_destroy(ocfs2_qf_chunk_cachep);
  1562. ocfs2_qf_chunk_cachep = NULL;
  1563. }
  1564. static int ocfs2_get_sector(struct super_block *sb,
  1565. struct buffer_head **bh,
  1566. int block,
  1567. int sect_size)
  1568. {
  1569. if (!sb_set_blocksize(sb, sect_size)) {
  1570. mlog(ML_ERROR, "unable to set blocksize\n");
  1571. return -EIO;
  1572. }
  1573. *bh = sb_getblk(sb, block);
  1574. if (!*bh) {
  1575. mlog_errno(-EIO);
  1576. return -EIO;
  1577. }
  1578. lock_buffer(*bh);
  1579. if (!buffer_dirty(*bh))
  1580. clear_buffer_uptodate(*bh);
  1581. unlock_buffer(*bh);
  1582. ll_rw_block(READ, 1, bh);
  1583. wait_on_buffer(*bh);
  1584. if (!buffer_uptodate(*bh)) {
  1585. mlog_errno(-EIO);
  1586. brelse(*bh);
  1587. *bh = NULL;
  1588. return -EIO;
  1589. }
  1590. return 0;
  1591. }
  1592. static int ocfs2_mount_volume(struct super_block *sb)
  1593. {
  1594. int status = 0;
  1595. int unlock_super = 0;
  1596. struct ocfs2_super *osb = OCFS2_SB(sb);
  1597. mlog_entry_void();
  1598. if (ocfs2_is_hard_readonly(osb))
  1599. goto leave;
  1600. status = ocfs2_dlm_init(osb);
  1601. if (status < 0) {
  1602. mlog_errno(status);
  1603. goto leave;
  1604. }
  1605. status = ocfs2_super_lock(osb, 1);
  1606. if (status < 0) {
  1607. mlog_errno(status);
  1608. goto leave;
  1609. }
  1610. unlock_super = 1;
  1611. /* This will load up the node map and add ourselves to it. */
  1612. status = ocfs2_find_slot(osb);
  1613. if (status < 0) {
  1614. mlog_errno(status);
  1615. goto leave;
  1616. }
  1617. /* load all node-local system inodes */
  1618. status = ocfs2_init_local_system_inodes(osb);
  1619. if (status < 0) {
  1620. mlog_errno(status);
  1621. goto leave;
  1622. }
  1623. status = ocfs2_check_volume(osb);
  1624. if (status < 0) {
  1625. mlog_errno(status);
  1626. goto leave;
  1627. }
  1628. status = ocfs2_truncate_log_init(osb);
  1629. if (status < 0)
  1630. mlog_errno(status);
  1631. leave:
  1632. if (unlock_super)
  1633. ocfs2_super_unlock(osb, 1);
  1634. mlog_exit(status);
  1635. return status;
  1636. }
  1637. static void ocfs2_dismount_volume(struct super_block *sb, int mnt_err)
  1638. {
  1639. int tmp, hangup_needed = 0;
  1640. struct ocfs2_super *osb = NULL;
  1641. char nodestr[8];
  1642. mlog_entry("(0x%p)\n", sb);
  1643. BUG_ON(!sb);
  1644. osb = OCFS2_SB(sb);
  1645. BUG_ON(!osb);
  1646. debugfs_remove(osb->osb_ctxt);
  1647. /*
  1648. * Flush inode dropping work queue so that deletes are
  1649. * performed while the filesystem is still working
  1650. */
  1651. ocfs2_drop_all_dl_inodes(osb);
  1652. /* Orphan scan should be stopped as early as possible */
  1653. ocfs2_orphan_scan_stop(osb);
  1654. ocfs2_disable_quotas(osb);
  1655. ocfs2_shutdown_local_alloc(osb);
  1656. ocfs2_truncate_log_shutdown(osb);
  1657. /* This will disable recovery and flush any recovery work. */
  1658. ocfs2_recovery_exit(osb);
  1659. ocfs2_journal_shutdown(osb);
  1660. ocfs2_sync_blockdev(sb);
  1661. ocfs2_purge_refcount_trees(osb);
  1662. /* No cluster connection means we've failed during mount, so skip
  1663. * all the steps which depended on that to complete. */
  1664. if (osb->cconn) {
  1665. tmp = ocfs2_super_lock(osb, 1);
  1666. if (tmp < 0) {
  1667. mlog_errno(tmp);
  1668. return;
  1669. }
  1670. }
  1671. if (osb->slot_num != OCFS2_INVALID_SLOT)
  1672. ocfs2_put_slot(osb);
  1673. if (osb->cconn)
  1674. ocfs2_super_unlock(osb, 1);
  1675. ocfs2_release_system_inodes(osb);
  1676. /*
  1677. * If we're dismounting due to mount error, mount.ocfs2 will clean
  1678. * up heartbeat. If we're a local mount, there is no heartbeat.
  1679. * If we failed before we got a uuid_str yet, we can't stop
  1680. * heartbeat. Otherwise, do it.
  1681. */
  1682. if (!mnt_err && !ocfs2_mount_local(osb) && osb->uuid_str)
  1683. hangup_needed = 1;
  1684. if (osb->cconn)
  1685. ocfs2_dlm_shutdown(osb, hangup_needed);
  1686. ocfs2_blockcheck_stats_debugfs_remove(&osb->osb_ecc_stats);
  1687. debugfs_remove(osb->osb_debug_root);
  1688. if (hangup_needed)
  1689. ocfs2_cluster_hangup(osb->uuid_str, strlen(osb->uuid_str));
  1690. atomic_set(&osb->vol_state, VOLUME_DISMOUNTED);
  1691. if (ocfs2_mount_local(osb))
  1692. snprintf(nodestr, sizeof(nodestr), "local");
  1693. else
  1694. snprintf(nodestr, sizeof(nodestr), "%u", osb->node_num);
  1695. printk(KERN_INFO "ocfs2: Unmounting device (%s) on (node %s)\n",
  1696. osb->dev_str, nodestr);
  1697. ocfs2_delete_osb(osb);
  1698. kfree(osb);
  1699. sb->s_dev = 0;
  1700. sb->s_fs_info = NULL;
  1701. }
  1702. static int ocfs2_setup_osb_uuid(struct ocfs2_super *osb, const unsigned char *uuid,
  1703. unsigned uuid_bytes)
  1704. {
  1705. int i, ret;
  1706. char *ptr;
  1707. BUG_ON(uuid_bytes != OCFS2_VOL_UUID_LEN);
  1708. osb->uuid_str = kzalloc(OCFS2_VOL_UUID_LEN * 2 + 1, GFP_KERNEL);
  1709. if (osb->uuid_str == NULL)
  1710. return -ENOMEM;
  1711. for (i = 0, ptr = osb->uuid_str; i < OCFS2_VOL_UUID_LEN; i++) {
  1712. /* print with null */
  1713. ret = snprintf(ptr, 3, "%02X", uuid[i]);
  1714. if (ret != 2) /* drop super cleans up */
  1715. return -EINVAL;
  1716. /* then only advance past the last char */
  1717. ptr += 2;
  1718. }
  1719. return 0;
  1720. }
  1721. static int ocfs2_initialize_super(struct super_block *sb,
  1722. struct buffer_head *bh,
  1723. int sector_size,
  1724. struct ocfs2_blockcheck_stats *stats)
  1725. {
  1726. int status;
  1727. int i, cbits, bbits;
  1728. struct ocfs2_dinode *di = (struct ocfs2_dinode *)bh->b_data;
  1729. struct inode *inode = NULL;
  1730. struct ocfs2_journal *journal;
  1731. __le32 uuid_net_key;
  1732. struct ocfs2_super *osb;
  1733. mlog_entry_void();
  1734. osb = kzalloc(sizeof(struct ocfs2_super), GFP_KERNEL);
  1735. if (!osb) {
  1736. status = -ENOMEM;
  1737. mlog_errno(status);
  1738. goto bail;
  1739. }
  1740. sb->s_fs_info = osb;
  1741. sb->s_op = &ocfs2_sops;
  1742. sb->s_export_op = &ocfs2_export_ops;
  1743. sb->s_qcop = &ocfs2_quotactl_ops;
  1744. sb->dq_op = &ocfs2_quota_operations;
  1745. sb->s_xattr = ocfs2_xattr_handlers;
  1746. sb->s_time_gran = 1;
  1747. sb->s_flags |= MS_NOATIME;
  1748. /* this is needed to support O_LARGEFILE */
  1749. cbits = le32_to_cpu(di->id2.i_super.s_clustersize_bits);
  1750. bbits = le32_to_cpu(di->id2.i_super.s_blocksize_bits);
  1751. sb->s_maxbytes = ocfs2_max_file_offset(bbits, cbits);
  1752. osb->osb_dx_mask = (1 << (cbits - bbits)) - 1;
  1753. for (i = 0; i < 3; i++)
  1754. osb->osb_dx_seed[i] = le32_to_cpu(di->id2.i_super.s_dx_seed[i]);
  1755. osb->osb_dx_seed[3] = le32_to_cpu(di->id2.i_super.s_uuid_hash);
  1756. osb->sb = sb;
  1757. /* Save off for ocfs2_rw_direct */
  1758. osb->s_sectsize_bits = blksize_bits(sector_size);
  1759. BUG_ON(!osb->s_sectsize_bits);
  1760. spin_lock_init(&osb->dc_task_lock);
  1761. init_waitqueue_head(&osb->dc_event);
  1762. osb->dc_work_sequence = 0;
  1763. osb->dc_wake_sequence = 0;
  1764. INIT_LIST_HEAD(&osb->blocked_lock_list);
  1765. osb->blocked_lock_count = 0;
  1766. spin_lock_init(&osb->osb_lock);
  1767. spin_lock_init(&osb->osb_xattr_lock);
  1768. ocfs2_init_steal_slots(osb);
  1769. atomic_set(&osb->alloc_stats.moves, 0);
  1770. atomic_set(&osb->alloc_stats.local_data, 0);
  1771. atomic_set(&osb->alloc_stats.bitmap_data, 0);
  1772. atomic_set(&osb->alloc_stats.bg_allocs, 0);
  1773. atomic_set(&osb->alloc_stats.bg_extends, 0);
  1774. /* Copy the blockcheck stats from the superblock probe */
  1775. osb->osb_ecc_stats = *stats;
  1776. ocfs2_init_node_maps(osb);
  1777. snprintf(osb->dev_str, sizeof(osb->dev_str), "%u,%u",
  1778. MAJOR(osb->sb->s_dev), MINOR(osb->sb->s_dev));
  1779. ocfs2_orphan_scan_init(osb);
  1780. status = ocfs2_recovery_init(osb);
  1781. if (status) {
  1782. mlog(ML_ERROR, "Unable to initialize recovery state\n");
  1783. mlog_errno(status);
  1784. goto bail;
  1785. }
  1786. init_waitqueue_head(&osb->checkpoint_event);
  1787. atomic_set(&osb->needs_checkpoint, 0);
  1788. osb->s_atime_quantum = OCFS2_DEFAULT_ATIME_QUANTUM;
  1789. osb->slot_num = OCFS2_INVALID_SLOT;
  1790. osb->s_xattr_inline_size = le16_to_cpu(
  1791. di->id2.i_super.s_xattr_inline_size);
  1792. osb->local_alloc_state = OCFS2_LA_UNUSED;
  1793. osb->local_alloc_bh = NULL;
  1794. INIT_DELAYED_WORK(&osb->la_enable_wq, ocfs2_la_enable_worker);
  1795. init_waitqueue_head(&osb->osb_mount_event);
  1796. status = ocfs2_resmap_init(osb, &osb->osb_la_resmap);
  1797. if (status) {
  1798. mlog_errno(status);
  1799. goto bail;
  1800. }
  1801. osb->vol_label = kmalloc(OCFS2_MAX_VOL_LABEL_LEN, GFP_KERNEL);
  1802. if (!osb->vol_label) {
  1803. mlog(ML_ERROR, "unable to alloc vol label\n");
  1804. status = -ENOMEM;
  1805. goto bail;
  1806. }
  1807. osb->max_slots = le16_to_cpu(di->id2.i_super.s_max_slots);
  1808. if (osb->max_slots > OCFS2_MAX_SLOTS || osb->max_slots == 0) {
  1809. mlog(ML_ERROR, "Invalid number of node slots (%u)\n",
  1810. osb->max_slots);
  1811. status = -EINVAL;
  1812. goto bail;
  1813. }
  1814. mlog(0, "max_slots for this device: %u\n", osb->max_slots);
  1815. osb->slot_recovery_generations =
  1816. kcalloc(osb->max_slots, sizeof(*osb->slot_recovery_generations),
  1817. GFP_KERNEL);
  1818. if (!osb->slot_recovery_generations) {
  1819. status = -ENOMEM;
  1820. mlog_errno(status);
  1821. goto bail;
  1822. }
  1823. init_waitqueue_head(&osb->osb_wipe_event);
  1824. osb->osb_orphan_wipes = kcalloc(osb->max_slots,
  1825. sizeof(*osb->osb_orphan_wipes),
  1826. GFP_KERNEL);
  1827. if (!osb->osb_orphan_wipes) {
  1828. status = -ENOMEM;
  1829. mlog_errno(status);
  1830. goto bail;
  1831. }
  1832. osb->osb_rf_lock_tree = RB_ROOT;
  1833. osb->s_feature_compat =
  1834. le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_compat);
  1835. osb->s_feature_ro_compat =
  1836. le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_ro_compat);
  1837. osb->s_feature_incompat =
  1838. le32_to_cpu(OCFS2_RAW_SB(di)->s_feature_incompat);
  1839. if ((i = OCFS2_HAS_INCOMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_INCOMPAT_SUPP))) {
  1840. mlog(ML_ERROR, "couldn't mount because of unsupported "
  1841. "optional features (%x).\n", i);
  1842. status = -EINVAL;
  1843. goto bail;
  1844. }
  1845. if (!(osb->sb->s_flags & MS_RDONLY) &&
  1846. (i = OCFS2_HAS_RO_COMPAT_FEATURE(osb->sb, ~OCFS2_FEATURE_RO_COMPAT_SUPP))) {
  1847. mlog(ML_ERROR, "couldn't mount RDWR because of "
  1848. "unsupported optional features (%x).\n", i);
  1849. status = -EINVAL;
  1850. goto bail;
  1851. }
  1852. if (ocfs2_userspace_stack(osb)) {
  1853. memcpy(osb->osb_cluster_stack,
  1854. OCFS2_RAW_SB(di)->s_cluster_info.ci_stack,
  1855. OCFS2_STACK_LABEL_LEN);
  1856. osb->osb_cluster_stack[OCFS2_STACK_LABEL_LEN] = '\0';
  1857. if (strlen(osb->osb_cluster_stack) != OCFS2_STACK_LABEL_LEN) {
  1858. mlog(ML_ERROR,
  1859. "couldn't mount because of an invalid "
  1860. "cluster stack label (%s) \n",
  1861. osb->osb_cluster_stack);
  1862. status = -EINVAL;
  1863. goto bail;
  1864. }
  1865. } else {
  1866. /* The empty string is identical with classic tools that
  1867. * don't know about s_cluster_info. */
  1868. osb->osb_cluster_stack[0] = '\0';
  1869. }
  1870. get_random_bytes(&osb->s_next_generation, sizeof(u32));
  1871. /* FIXME
  1872. * This should be done in ocfs2_journal_init(), but unknown
  1873. * ordering issues will cause the filesystem to crash.
  1874. * If anyone wants to figure out what part of the code
  1875. * refers to osb->journal before ocfs2_journal_init() is run,
  1876. * be my guest.
  1877. */
  1878. /* initialize our journal structure */
  1879. journal = kzalloc(sizeof(struct ocfs2_journal), GFP_KERNEL);
  1880. if (!journal) {
  1881. mlog(ML_ERROR, "unable to alloc journal\n");
  1882. status = -ENOMEM;
  1883. goto bail;
  1884. }
  1885. osb->journal = journal;
  1886. journal->j_osb = osb;
  1887. atomic_set(&journal->j_num_trans, 0);
  1888. init_rwsem(&journal->j_trans_barrier);
  1889. init_waitqueue_head(&journal->j_checkpointed);
  1890. spin_lock_init(&journal->j_lock);
  1891. journal->j_trans_id = (unsigned long) 1;
  1892. INIT_LIST_HEAD(&journal->j_la_cleanups);
  1893. INIT_WORK(&journal->j_recovery_work, ocfs2_complete_recovery);
  1894. journal->j_state = OCFS2_JOURNAL_FREE;
  1895. INIT_WORK(&osb->dentry_lock_work, ocfs2_drop_dl_inodes);
  1896. osb->dentry_lock_list = NULL;
  1897. /* get some pseudo constants for clustersize bits */
  1898. osb->s_clustersize_bits =
  1899. le32_to_cpu(di->id2.i_super.s_clustersize_bits);
  1900. osb->s_clustersize = 1 << osb->s_clustersize_bits;
  1901. mlog(0, "clusterbits=%d\n", osb->s_clustersize_bits);
  1902. if (osb->s_clustersize < OCFS2_MIN_CLUSTERSIZE ||
  1903. osb->s_clustersize > OCFS2_MAX_CLUSTERSIZE) {
  1904. mlog(ML_ERROR, "Volume has invalid cluster size (%d)\n",
  1905. osb->s_clustersize);
  1906. status = -EINVAL;
  1907. goto bail;
  1908. }
  1909. if (ocfs2_clusters_to_blocks(osb->sb, le32_to_cpu(di->i_clusters) - 1)
  1910. > (u32)~0UL) {
  1911. mlog(ML_ERROR, "Volume might try to write to blocks beyond "
  1912. "what jbd can address in 32 bits.\n");
  1913. status = -EINVAL;
  1914. goto bail;
  1915. }
  1916. if (ocfs2_setup_osb_uuid(osb, di->id2.i_super.s_uuid,
  1917. sizeof(di->id2.i_super.s_uuid))) {
  1918. mlog(ML_ERROR, "Out of memory trying to setup our uuid.\n");
  1919. status = -ENOMEM;
  1920. goto bail;
  1921. }
  1922. memcpy(&uuid_net_key, di->id2.i_super.s_uuid, sizeof(uuid_net_key));
  1923. strncpy(osb->vol_label, di->id2.i_super.s_label, 63);
  1924. osb->vol_label[63] = '\0';
  1925. osb->root_blkno = le64_to_cpu(di->id2.i_super.s_root_blkno);
  1926. osb->system_dir_blkno = le64_to_cpu(di->id2.i_super.s_system_dir_blkno);
  1927. osb->first_cluster_group_blkno =
  1928. le64_to_cpu(di->id2.i_super.s_first_cluster_group);
  1929. osb->fs_generation = le32_to_cpu(di->i_fs_generation);
  1930. osb->uuid_hash = le32_to_cpu(di->id2.i_super.s_uuid_hash);
  1931. mlog(0, "vol_label: %s\n", osb->vol_label);
  1932. mlog(0, "uuid: %s\n", osb->uuid_str);
  1933. mlog(0, "root_blkno=%llu, system_dir_blkno=%llu\n",
  1934. (unsigned long long)osb->root_blkno,
  1935. (unsigned long long)osb->system_dir_blkno);
  1936. osb->osb_dlm_debug = ocfs2_new_dlm_debug();
  1937. if (!osb->osb_dlm_debug) {
  1938. status = -ENOMEM;
  1939. mlog_errno(status);
  1940. goto bail;
  1941. }
  1942. atomic_set(&osb->vol_state, VOLUME_INIT);
  1943. /* load root, system_dir, and all global system inodes */
  1944. status = ocfs2_init_global_system_inodes(osb);
  1945. if (status < 0) {
  1946. mlog_errno(status);
  1947. goto bail;
  1948. }
  1949. /*
  1950. * global bitmap
  1951. */
  1952. inode = ocfs2_get_system_file_inode(osb, GLOBAL_BITMAP_SYSTEM_INODE,
  1953. OCFS2_INVALID_SLOT);
  1954. if (!inode) {
  1955. status = -EINVAL;
  1956. mlog_errno(status);
  1957. goto bail;
  1958. }
  1959. osb->bitmap_blkno = OCFS2_I(inode)->ip_blkno;
  1960. osb->osb_clusters_at_boot = OCFS2_I(inode)->ip_clusters;
  1961. iput(inode);
  1962. osb->bitmap_cpg = ocfs2_group_bitmap_size(sb, 0,
  1963. osb->s_feature_incompat) * 8;
  1964. status = ocfs2_init_slot_info(osb);
  1965. if (status < 0) {
  1966. mlog_errno(status);
  1967. goto bail;
  1968. }
  1969. bail:
  1970. mlog_exit(status);
  1971. return status;
  1972. }
  1973. /*
  1974. * will return: -EAGAIN if it is ok to keep searching for superblocks
  1975. * -EINVAL if there is a bad superblock
  1976. * 0 on success
  1977. */
  1978. static int ocfs2_verify_volume(struct ocfs2_dinode *di,
  1979. struct buffer_head *bh,
  1980. u32 blksz,
  1981. struct ocfs2_blockcheck_stats *stats)
  1982. {
  1983. int status = -EAGAIN;
  1984. mlog_entry_void();
  1985. if (memcmp(di->i_signature, OCFS2_SUPER_BLOCK_SIGNATURE,
  1986. strlen(OCFS2_SUPER_BLOCK_SIGNATURE)) == 0) {
  1987. /* We have to do a raw check of the feature here */
  1988. if (le32_to_cpu(di->id2.i_super.s_feature_incompat) &
  1989. OCFS2_FEATURE_INCOMPAT_META_ECC) {
  1990. status = ocfs2_block_check_validate(bh->b_data,
  1991. bh->b_size,
  1992. &di->i_check,
  1993. stats);
  1994. if (status)
  1995. goto out;
  1996. }
  1997. status = -EINVAL;
  1998. if ((1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits)) != blksz) {
  1999. mlog(ML_ERROR, "found superblock with incorrect block "
  2000. "size: found %u, should be %u\n",
  2001. 1 << le32_to_cpu(di->id2.i_super.s_blocksize_bits),
  2002. blksz);
  2003. } else if (le16_to_cpu(di->id2.i_super.s_major_rev_level) !=
  2004. OCFS2_MAJOR_REV_LEVEL ||
  2005. le16_to_cpu(di->id2.i_super.s_minor_rev_level) !=
  2006. OCFS2_MINOR_REV_LEVEL) {
  2007. mlog(ML_ERROR, "found superblock with bad version: "
  2008. "found %u.%u, should be %u.%u\n",
  2009. le16_to_cpu(di->id2.i_super.s_major_rev_level),
  2010. le16_to_cpu(di->id2.i_super.s_minor_rev_level),
  2011. OCFS2_MAJOR_REV_LEVEL,
  2012. OCFS2_MINOR_REV_LEVEL);
  2013. } else if (bh->b_blocknr != le64_to_cpu(di->i_blkno)) {
  2014. mlog(ML_ERROR, "bad block number on superblock: "
  2015. "found %llu, should be %llu\n",
  2016. (unsigned long long)le64_to_cpu(di->i_blkno),
  2017. (unsigned long long)bh->b_blocknr);
  2018. } else if (le32_to_cpu(di->id2.i_super.s_clustersize_bits) < 12 ||
  2019. le32_to_cpu(di->id2.i_super.s_clustersize_bits) > 20) {
  2020. mlog(ML_ERROR, "bad cluster size found: %u\n",
  2021. 1 << le32_to_cpu(di->id2.i_super.s_clustersize_bits));
  2022. } else if (!le64_to_cpu(di->id2.i_super.s_root_blkno)) {
  2023. mlog(ML_ERROR, "bad root_blkno: 0\n");
  2024. } else if (!le64_to_cpu(di->id2.i_super.s_system_dir_blkno)) {
  2025. mlog(ML_ERROR, "bad system_dir_blkno: 0\n");
  2026. } else if (le16_to_cpu(di->id2.i_super.s_max_slots) > OCFS2_MAX_SLOTS) {
  2027. mlog(ML_ERROR,
  2028. "Superblock slots found greater than file system "
  2029. "maximum: found %u, max %u\n",
  2030. le16_to_cpu(di->id2.i_super.s_max_slots),
  2031. OCFS2_MAX_SLOTS);
  2032. } else {
  2033. /* found it! */
  2034. status = 0;
  2035. }
  2036. }
  2037. out:
  2038. mlog_exit(status);
  2039. return status;
  2040. }
  2041. static int ocfs2_check_volume(struct ocfs2_super *osb)
  2042. {
  2043. int status;
  2044. int dirty;
  2045. int local;
  2046. struct ocfs2_dinode *local_alloc = NULL; /* only used if we
  2047. * recover
  2048. * ourselves. */
  2049. mlog_entry_void();
  2050. /* Init our journal object. */
  2051. status = ocfs2_journal_init(osb->journal, &dirty);
  2052. if (status < 0) {
  2053. mlog(ML_ERROR, "Could not initialize journal!\n");
  2054. goto finally;
  2055. }
  2056. /* If the journal was unmounted cleanly then we don't want to
  2057. * recover anything. Otherwise, journal_load will do that
  2058. * dirty work for us :) */
  2059. if (!dirty) {
  2060. status = ocfs2_journal_wipe(osb->journal, 0);
  2061. if (status < 0) {
  2062. mlog_errno(status);
  2063. goto finally;
  2064. }
  2065. } else {
  2066. mlog(ML_NOTICE, "File system was not unmounted cleanly, "
  2067. "recovering volume.\n");
  2068. }
  2069. local = ocfs2_mount_local(osb);
  2070. /* will play back anything left in the journal. */
  2071. status = ocfs2_journal_load(osb->journal, local, dirty);
  2072. if (status < 0) {
  2073. mlog(ML_ERROR, "ocfs2 journal load failed! %d\n", status);
  2074. goto finally;
  2075. }
  2076. if (dirty) {
  2077. /* recover my local alloc if we didn't unmount cleanly. */
  2078. status = ocfs2_begin_local_alloc_recovery(osb,
  2079. osb->slot_num,
  2080. &local_alloc);
  2081. if (status < 0) {
  2082. mlog_errno(status);
  2083. goto finally;
  2084. }
  2085. /* we complete the recovery process after we've marked
  2086. * ourselves as mounted. */
  2087. }
  2088. mlog(0, "Journal loaded.\n");
  2089. status = ocfs2_load_local_alloc(osb);
  2090. if (status < 0) {
  2091. mlog_errno(status);
  2092. goto finally;
  2093. }
  2094. if (dirty) {
  2095. /* Recovery will be completed after we've mounted the
  2096. * rest of the volume. */
  2097. osb->dirty = 1;
  2098. osb->local_alloc_copy = local_alloc;
  2099. local_alloc = NULL;
  2100. }
  2101. /* go through each journal, trylock it and if you get the
  2102. * lock, and it's marked as dirty, set the bit in the recover
  2103. * map and launch a recovery thread for it. */
  2104. status = ocfs2_mark_dead_nodes(osb);
  2105. if (status < 0) {
  2106. mlog_errno(status);
  2107. goto finally;
  2108. }
  2109. status = ocfs2_compute_replay_slots(osb);
  2110. if (status < 0)
  2111. mlog_errno(status);
  2112. finally:
  2113. if (local_alloc)
  2114. kfree(local_alloc);
  2115. mlog_exit(status);
  2116. return status;
  2117. }
  2118. /*
  2119. * The routine gets called from dismount or close whenever a dismount on
  2120. * volume is requested and the osb open count becomes 1.
  2121. * It will remove the osb from the global list and also free up all the
  2122. * initialized resources and fileobject.
  2123. */
  2124. static void ocfs2_delete_osb(struct ocfs2_super *osb)
  2125. {
  2126. mlog_entry_void();
  2127. /* This function assumes that the caller has the main osb resource */
  2128. ocfs2_free_slot_info(osb);
  2129. kfree(osb->osb_orphan_wipes);
  2130. kfree(osb->slot_recovery_generations);
  2131. /* FIXME
  2132. * This belongs in journal shutdown, but because we have to
  2133. * allocate osb->journal at the start of ocfs2_initalize_osb(),
  2134. * we free it here.
  2135. */
  2136. kfree(osb->journal);
  2137. if (osb->local_alloc_copy)
  2138. kfree(osb->local_alloc_copy);
  2139. kfree(osb->uuid_str);
  2140. ocfs2_put_dlm_debug(osb->osb_dlm_debug);
  2141. memset(osb, 0, sizeof(struct ocfs2_super));
  2142. mlog_exit_void();
  2143. }
  2144. /* Put OCFS2 into a readonly state, or (if the user specifies it),
  2145. * panic(). We do not support continue-on-error operation. */
  2146. static void ocfs2_handle_error(struct super_block *sb)
  2147. {
  2148. struct ocfs2_super *osb = OCFS2_SB(sb);
  2149. if (osb->s_mount_opt & OCFS2_MOUNT_ERRORS_PANIC)
  2150. panic("OCFS2: (device %s): panic forced after error\n",
  2151. sb->s_id);
  2152. ocfs2_set_osb_flag(osb, OCFS2_OSB_ERROR_FS);
  2153. if (sb->s_flags & MS_RDONLY &&
  2154. (ocfs2_is_soft_readonly(osb) ||
  2155. ocfs2_is_hard_readonly(osb)))
  2156. return;
  2157. printk(KERN_CRIT "File system is now read-only due to the potential "
  2158. "of on-disk corruption. Please run fsck.ocfs2 once the file "
  2159. "system is unmounted.\n");
  2160. sb->s_flags |= MS_RDONLY;
  2161. ocfs2_set_ro_flag(osb, 0);
  2162. }
  2163. static char error_buf[1024];
  2164. void __ocfs2_error(struct super_block *sb,
  2165. const char *function,
  2166. const char *fmt, ...)
  2167. {
  2168. va_list args;
  2169. va_start(args, fmt);
  2170. vsnprintf(error_buf, sizeof(error_buf), fmt, args);
  2171. va_end(args);
  2172. /* Not using mlog here because we want to show the actual
  2173. * function the error came from. */
  2174. printk(KERN_CRIT "OCFS2: ERROR (device %s): %s: %s\n",
  2175. sb->s_id, function, error_buf);
  2176. ocfs2_handle_error(sb);
  2177. }
  2178. /* Handle critical errors. This is intentionally more drastic than
  2179. * ocfs2_handle_error, so we only use for things like journal errors,
  2180. * etc. */
  2181. void __ocfs2_abort(struct super_block* sb,
  2182. const char *function,
  2183. const char *fmt, ...)
  2184. {
  2185. va_list args;
  2186. va_start(args, fmt);
  2187. vsnprintf(error_buf, sizeof(error_buf), fmt, args);
  2188. va_end(args);
  2189. printk(KERN_CRIT "OCFS2: abort (device %s): %s: %s\n",
  2190. sb->s_id, function, error_buf);
  2191. /* We don't have the cluster support yet to go straight to
  2192. * hard readonly in here. Until then, we want to keep
  2193. * ocfs2_abort() so that we can at least mark critical
  2194. * errors.
  2195. *
  2196. * TODO: This should abort the journal and alert other nodes
  2197. * that our slot needs recovery. */
  2198. /* Force a panic(). This stinks, but it's better than letting
  2199. * things continue without having a proper hard readonly
  2200. * here. */
  2201. if (!ocfs2_mount_local(OCFS2_SB(sb)))
  2202. OCFS2_SB(sb)->s_mount_opt |= OCFS2_MOUNT_ERRORS_PANIC;
  2203. ocfs2_handle_error(sb);
  2204. }
  2205. /*
  2206. * Void signal blockers, because in-kernel sigprocmask() only fails
  2207. * when SIG_* is wrong.
  2208. */
  2209. void ocfs2_block_signals(sigset_t *oldset)
  2210. {
  2211. int rc;
  2212. sigset_t blocked;
  2213. sigfillset(&blocked);
  2214. rc = sigprocmask(SIG_BLOCK, &blocked, oldset);
  2215. BUG_ON(rc);
  2216. }
  2217. void ocfs2_unblock_signals(sigset_t *oldset)
  2218. {
  2219. int rc = sigprocmask(SIG_SETMASK, oldset, NULL);
  2220. BUG_ON(rc);
  2221. }
  2222. module_init(ocfs2_init);
  2223. module_exit(ocfs2_exit);