From owner-svn-src-projects@FreeBSD.ORG Mon Oct 14 20:56:52 2013 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 5916B3DC; Mon, 14 Oct 2013 20:56:52 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 3745427A9; Mon, 14 Oct 2013 20:56:52 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9EKuqkh052581; Mon, 14 Oct 2013 20:56:52 GMT (envelope-from asomers@svn.freebsd.org) Received: (from asomers@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9EKup26052579; Mon, 14 Oct 2013 20:56:51 GMT (envelope-from asomers@svn.freebsd.org) Message-Id: <201310142056.r9EKup26052579@svn.freebsd.org> From: Alan Somers Date: Mon, 14 Oct 2013 20:56:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r256453 - projects/zfsd/head/cddl/sbin/zfsd X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Oct 2013 20:56:52 -0000 Author: asomers Date: Mon Oct 14 20:56:51 2013 New Revision: 256453 URL: http://svnweb.freebsd.org/changeset/base/256453 Log: In the static method CaseFile::DeSerializeFile(), break out the acutal parsing of the serialization stream into the instance method CaseFile::DeSerialize(ifstream &caseStream). cddl/sbin/zfsd/case_file.h: Declaration of CaseFile::DeSerialize(). cddl/sbin/zfsd/case_file.cc: o Factor out CaseFile::DeSerialize() from CaseFile::DeSerializeFile(). o In CaseFile::DeSerialize() remove a superfluous return statement after a throw. Submitted by: gibbs Approved by: ken (mentor) Sponsored by: Spectra Logic Corporation Modified: projects/zfsd/head/cddl/sbin/zfsd/case_file.cc projects/zfsd/head/cddl/sbin/zfsd/case_file.h Modified: projects/zfsd/head/cddl/sbin/zfsd/case_file.cc ============================================================================== --- projects/zfsd/head/cddl/sbin/zfsd/case_file.cc Mon Oct 14 20:53:51 2013 (r256452) +++ projects/zfsd/head/cddl/sbin/zfsd/case_file.cc Mon Oct 14 20:56:51 2013 (r256453) @@ -552,7 +552,6 @@ void CaseFile::DeSerializeFile(const char *fileName) { string fullName(s_caseFilePath + '/' + fileName); - string evString; CaseFile *existingCaseFile(NULL); CaseFile *caseFile(NULL); @@ -603,50 +602,11 @@ CaseFile::DeSerializeFile(const char *fi } ifstream caseStream(fullName.c_str()); - if (!caseStream) { + if (!caseStream) throw ZfsdException("CaseFile::DeSerialize: Unable to " "read %s.\n", fileName); - return; - } - stringstream fakeDevdSocket(stringstream::in|stringstream::out); - IstreamReader caseReader(&fakeDevdSocket); - /* Re-load EventData */ - EventBuffer eventBuffer(caseReader); - caseStream >> std::noskipws >> std::ws; - while (!caseStream.eof()) { - /* - * Outline: - * read the beginning of a line and check it for - * "tentative". If found, discard "tentative". - * Shove into fakeDevdSocket. - * call ExtractEvent - * continue - */ - DevCtlEventList* destEvents; - string tentFlag("tentative "); - string line; - std::stringbuf lineBuf; - caseStream.get(lineBuf); - caseStream.ignore(); /*discard the newline character*/ - line = lineBuf.str(); - if (line.compare(0, tentFlag.size(), tentFlag) == 0) { - line.erase(0, tentFlag.size()); - destEvents = &caseFile->m_tentativeEvents; - } else { - destEvents = &caseFile->m_events; - } - fakeDevdSocket << line; - fakeDevdSocket << '\n'; - while (eventBuffer.ExtractEvent(evString)) { - DevCtlEvent *event(DevCtlEvent::CreateEvent( - evString)); - if (event != NULL) { - destEvents->push_back(event); - caseFile->RegisterCallout(*event); - } - } - } + caseFile->DeSerialize(caseStream); } catch (const ParseException &exp) { exp.Log(); @@ -759,6 +719,50 @@ CaseFile::Serialize() } void +CaseFile::DeSerialize(ifstream &caseStream) +{ + stringstream fakeDevdSocket(stringstream::in|stringstream::out); + IstreamReader caseReader(&fakeDevdSocket); + EventBuffer eventBuffer(caseReader); + string evString; + + caseStream >> std::noskipws >> std::ws; + while (!caseStream.eof()) { + /* + * Outline: + * read the beginning of a line and check it for + * "tentative". If found, discard "tentative". + * Shove into fakeDevdSocket. + * call ExtractEvent + * continue + */ + DevCtlEventList* destEvents; + string tentFlag("tentative "); + string line; + std::stringbuf lineBuf; + + caseStream.get(lineBuf); + caseStream.ignore(); /*discard the newline character*/ + line = lineBuf.str(); + if (line.compare(0, tentFlag.size(), tentFlag) == 0) { + line.erase(0, tentFlag.size()); + destEvents = &m_tentativeEvents; + } else { + destEvents = &m_events; + } + fakeDevdSocket << line; + fakeDevdSocket << '\n'; + while (eventBuffer.ExtractEvent(evString)) { + DevCtlEvent *event(DevCtlEvent::CreateEvent(evString)); + if (event != NULL) { + destEvents->push_back(event); + RegisterCallout(*event); + } + } + } +} + +void CaseFile::Close() { /* Modified: projects/zfsd/head/cddl/sbin/zfsd/case_file.h ============================================================================== --- projects/zfsd/head/cddl/sbin/zfsd/case_file.h Mon Oct 14 20:53:51 2013 (r256452) +++ projects/zfsd/head/cddl/sbin/zfsd/case_file.h Mon Oct 14 20:56:51 2013 (r256453) @@ -255,6 +255,13 @@ protected: void Serialize(); /** + * \brief Retrieve event data from a serialization stream. + * + * \param caseStream The serializtion stream to parse. + */ + void DeSerialize(std::ifstream &caseStream); + + /** * \brief Serializes the supplied event list and writes it to fd * * \param prefix If not NULL, this prefix will be prepended to