super.c 65 KB

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