super.c 68 KB

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