super.c 69 KB

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