Commit 836c4ac1 authored by Christian Jürges's avatar Christian Jürges
Browse files

fixed wrong nfs umount handling

parent 542c121d
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="085b6e34-2887-457c-96ef-ca9c937a2df8" name="Default Changelist" comment="" />
<list default="true" id="085b6e34-2887-457c-96ef-ca9c937a2df8" name="Default Changelist" comment="">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/localfs.go" beforeDir="false" afterPath="$PROJECT_DIR$/localfs.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/nfsfs.go" beforeDir="false" afterPath="$PROJECT_DIR$/nfsfs.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/umounter.go" beforeDir="false" afterPath="$PROJECT_DIR$/umounter.go" afterDir="false" />
</list>
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
......@@ -10,11 +15,11 @@
</component>
<component name="FileEditorManager">
<leaf SIDE_TABS_SIZE_LIMIT_KEY="300">
<file pinned="false" current-in-tab="false">
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/umounter.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="765">
<caret line="51" column="5" selection-start-line="49" selection-start-column="4" selection-end-line="51" selection-end-column="5" />
<state relative-caret-position="300">
<caret line="99" column="60" selection-start-line="99" selection-start-column="60" selection-end-line="99" selection-end-column="60" />
<folding>
<element signature="e#14#148#0" expanded="true" />
</folding>
......@@ -25,8 +30,8 @@
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/localfs.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1650">
<caret line="110" column="48" selection-start-line="110" selection-start-column="48" selection-end-line="110" selection-end-column="48" />
<state relative-caret-position="1230">
<caret line="193" column="32" selection-start-line="193" selection-start-column="32" selection-end-line="193" selection-end-column="32" />
<folding>
<element signature="e#14#74#0" expanded="true" />
</folding>
......@@ -34,11 +39,41 @@
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="true">
<file pinned="false" current-in-tab="false">
<entry file="file:///usr/local/Cellar/go/1.11.2/libexec/src/io/ioutil/ioutil.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="330">
<caret line="96" column="19" selection-start-line="96" selection-start-column="19" selection-end-line="96" selection-end-column="19" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file:///usr/local/Cellar/go/1.11.2/libexec/src/os/file.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-1503">
<caret line="10" column="13" selection-start-line="10" selection-start-column="4" selection-end-line="10" selection-end-column="13" />
<folding>
<element signature="e#1443#1536#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file:///usr/local/Cellar/go/1.11.2/libexec/src/os/file_unix.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="331">
<caret line="178" column="5" selection-start-line="178" selection-start-column="5" selection-end-line="178" selection-end-column="5" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/nfsfs.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="180">
<caret line="12" column="26" selection-start-line="12" selection-start-column="26" selection-end-line="12" selection-end-column="26" />
<state relative-caret-position="592">
<caret line="62" column="51" lean-forward="true" selection-start-line="62" selection-start-column="51" selection-end-line="62" selection-end-column="51" />
</state>
</provider>
</entry>
......@@ -74,9 +109,13 @@
<findStrings>
<find>umountByLocalPath</find>
<find>localNFSMountMap</find>
<find>PathError</find>
</findStrings>
</component>
<component name="GOROOT" path="/usr/local/Cellar/go/1.11.2/libexec" />
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
......@@ -89,16 +128,17 @@
</option>
</component>
<component name="ProjectFrameBounds">
<option name="x" value="1527" />
<option name="y" value="-486" />
<option name="width" value="1661" />
<option name="height" value="1054" />
<option name="x" value="67" />
<option name="y" value="23" />
<option name="width" value="1726" />
<option name="height" value="1112" />
</component>
<component name="ProjectView">
<navigator proportions="" version="1">
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="Scope" />
<pane id="ProjectPane">
<subPane>
<expand>
......@@ -106,11 +146,14 @@
<item name="zfsumounter" type="b2602c69:ProjectViewProjectNode" />
<item name="zfsumounter" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="zfsumounter" type="b2602c69:ProjectViewProjectNode" />
<item name="External Libraries" type="cb654da1:ExternalLibrariesNode" />
</path>
</expand>
<select />
</subPane>
</pane>
<pane id="Scope" />
</panes>
</component>
<component name="PropertiesComponent">
......@@ -139,10 +182,10 @@
</option>
</component>
<component name="ToolWindowManager">
<frame x="1527" y="-486" width="1661" height="1054" extended-state="0" />
<frame x="67" y="23" width="1726" height="1112" extended-state="0" />
<editor active="true" />
<layout>
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.22112416" />
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.21496437" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info id="Favorites" order="2" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" />
......@@ -154,7 +197,7 @@
<window_info anchor="bottom" id="TODO" order="6" />
<window_info anchor="bottom" id="Docker" order="7" />
<window_info anchor="bottom" id="Version Control" order="8" />
<window_info active="true" anchor="bottom" id="File Transfer" order="9" visible="true" weight="0.32848233" />
<window_info active="true" anchor="bottom" id="File Transfer" order="9" visible="true" weight="0.32843137" />
<window_info anchor="bottom" id="Database Changes" order="10" />
<window_info anchor="bottom" id="Terminal" order="11" />
<window_info anchor="bottom" id="Event Log" order="12" side_tool="true" />
......@@ -167,6 +210,18 @@
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="1" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/localfs.go</url>
<line>39</line>
<properties />
<option name="timeStamp" value="1" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
</component>
<component name="editorHistoryManager">
<entry file="file:///usr/local/Cellar/go/1.11.2/libexec/src/os/exec/exec.go">
<provider selected="true" editor-type-id="text-editor">
......@@ -189,30 +244,54 @@
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/localfs.go">
<entry file="file:///usr/local/Cellar/go/1.11.2/libexec/src/os/file_unix.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="331">
<caret line="178" column="5" selection-start-line="178" selection-start-column="5" selection-end-line="178" selection-end-column="5" />
</state>
</provider>
</entry>
<entry file="file:///usr/local/Cellar/go/1.11.2/libexec/src/io/ioutil/ioutil.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1650">
<caret line="110" column="48" selection-start-line="110" selection-start-column="48" selection-end-line="110" selection-end-column="48" />
<state relative-caret-position="330">
<caret line="96" column="19" selection-start-line="96" selection-start-column="19" selection-end-line="96" selection-end-column="19" />
</state>
</provider>
</entry>
<entry file="file:///usr/local/Cellar/go/1.11.2/libexec/src/os/file.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-1503">
<caret line="10" column="13" selection-start-line="10" selection-start-column="4" selection-end-line="10" selection-end-column="13" />
<folding>
<element signature="e#14#74#0" expanded="true" />
<element signature="e#1443#1536#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/umounter.go">
<entry file="file://$PROJECT_DIR$/nfsfs.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="765">
<caret line="51" column="5" selection-start-line="49" selection-start-column="4" selection-end-line="51" selection-end-column="5" />
<state relative-caret-position="592">
<caret line="62" column="51" lean-forward="true" selection-start-line="62" selection-start-column="51" selection-end-line="62" selection-end-column="51" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/localfs.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1230">
<caret line="193" column="32" selection-start-line="193" selection-start-column="32" selection-end-line="193" selection-end-column="32" />
<folding>
<element signature="e#14#148#0" expanded="true" />
<element signature="e#14#74#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/nfsfs.go">
<entry file="file://$PROJECT_DIR$/umounter.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="180">
<caret line="12" column="26" selection-start-line="12" selection-start-column="26" selection-end-line="12" selection-end-column="26" />
<state relative-caret-position="300">
<caret line="99" column="60" selection-start-line="99" selection-start-column="60" selection-end-line="99" selection-end-column="60" />
<folding>
<element signature="e#14#148#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
......
......@@ -66,6 +66,7 @@ func verifyLocalNFSMounts() {
err := umountByLocalPath(v.localPath)
if err != nil {
localNFSMountMap[k].unmountFailCount++
log.Errorf("failed attempt #%d unmounting %v", localNFSMountMap[k].unmountFailCount, v.localPath)
} else {
localNFSMountMap[k].isDeleted = true
}
......@@ -73,7 +74,27 @@ func verifyLocalNFSMounts() {
localNFSMountMap[k].unmountFailCount = 0
}
}
}
// find dead local nfs mounts
// for example after a zfs dataset was renamed on the zfs nfs server
func findAndFixDeadNfsMounts() {
// find nfs mounts only locally existing
for k, v := range localNFSMountMap {
if !v.isDeleted {
// find path key in nfs export map
if _, ok := nfsExportMap[k]; !ok {
log.Warningf("%v doest not exists on nfs server", v.localPath)
err := umountByLocalPath(v.localPath)
if err != nil {
localNFSMountMap[k].unmountFailCount++
log.Errorf("failed attempt #%d unmounting %v", localNFSMountMap[k].unmountFailCount, v.localPath)
} else {
localNFSMountMap[k].isDeleted = true
}
}
}
}
}
// read linux /proc/mounts and
......@@ -156,19 +177,21 @@ func getMountsLinux() (string, error) {
}
// check if local directory is readable
// and detect stale
func isPathIsStale(localPath string) bool {
log.Debug("trying to read localPath", localPath)
_, err := ioutil.ReadDir(localPath)
var isStale = false
if err != nil {
log.Error(err)
// isStale = strings.Contains(err.Error(), "stale")
isStale = true
isStale = strings.Contains(err.Error(), "stale")
// isStale = true
}
return isStale
}
// umoumt by local path
// umoumt by local path by
// calling system utility umount
func umountByLocalPath(localPath string) error {
log.Info("trying to umount", localPath)
c := command{Command: "/bin/umount"}
......
......@@ -42,7 +42,7 @@ func getNFSExports() {
n.Path = l[0]
// only add wanted directories
if strings.HasPrefix(n.Path, fullZfsServerPath) {
// log.Debug("adding", n.Path)
log.Debug("adding", n.Path)
localPath := createLocalPath(n.Path)
n.Options = l[1]
nfsExports = append(nfsExports, n)
......
......@@ -85,7 +85,9 @@ func main() {
getMountsLinux()
// verify local NFS mounted directories
verifyLocalNFSMounts()
//
// find and fix dead nfs mounts
findAndFixDeadNfsMounts()
// incr counter
pollCounter++
// log.Printf("waiting 10 seconds before releasing the mutex lock...")
// time.Sleep(10 * time.Second)
......@@ -95,10 +97,9 @@ func main() {
}
}()
// connect to zfs rest api and wait for dataset messages
for {
conn, err := net.Dial("tcp", opts.ZfsRestServerAddress)
if err != nil {
log.Error(err)
time.Sleep(5 * time.Second)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment