Monday, September 3, 2012

iOS and MTP USB Device installation failure

Getting iOS devices to sync on iTunes is easy, but somehow one of my PC no longer allow me to access my iphone internal storage through Windows Explorer running Windows 7 x64 OS. Multiple attempt to install the device driver failed saying I already have he current driver. When forced the Apple mobile device driver install, I run into the following error:
You may receive an error message when you try to install a device driver on a computer that is running an x64-based version of Windows
I have tried many things with no success, including using a different usb port(s), uninstalling/reinstalling (repair as well as clean install) latest version of Apple iTunes software and even try force install from the inf file directly from the following driver install patch C:\Program Files\Common Files\Apple\Mobile Device Support\Drivers which conveniently pop up a install error dialog:
The INF file you selected does not support this method of installation.
I checked to device manager and confirmed that the Apple Mobile Device USB driver did installed successfully under Universal Serial Bus controller and also verify Apple Mobile Device service is running. However, under the Portable Devices, the MTP USB Driver shows a persistent yellow warning about driver install failure instead of Apple iPhone on my other Windows 7 desktop.

I am not aware of any 3rd party tools that allow tracing the windows driver installation and detection, and failure to install the correct driver is the source of this current problem. I concluded that one needs to install the iTunes software first before attaching the iOS device for the iOS device to be detected properly and if the generic USB aka MTP USB device got installed first by Windows, it can quickly become messy to a point of no return and I surely have no plans to re-install the OS.

The goal is simple. I need to completely get rid of associate Apple iTunes software and Apple Mobile Device USB driver and I want Windows OS to properly detect the iOS device as if it sees the iOS device for the first time. A simple uninstall the Apple software won't be enough. So here are the steps to do fix correctly.

  1. Plug the iPhone in
  2. Go to Device manager >Universal Serial Bus controllers and delete the Apple Mobile USB instance
  3. Open Windows Registry (Admin Elevated Mode) and export the following registry key (so in case I fast fingered, I can revert the change easily): HKLM>system>current control set>control>class>{EEC5AD98-8080-425F-922A-DABF3DE3F69A} and then delete the following key: HKLM>system>current control set>control>class>{EEC5AD98-8080-425F-922A-DABF3DE3F69A}\UpperFilters
  4. Uninstall Apple Mobile Device Support
  5. Uninstall iTunes
  6. Unplug the iPhone and reboot
  7. Log back in to reinstall iTunes
  8. Unlock you phone and launch to camera app and make sure you have some photo there. If not, just snap a photo
  9. Plug iPhone back in to the USB port and let the plug and play do it's magic
Viola.. plug and pray is activated and everything is now properly detected. I am now able to access the iOS internal storage to get to the photos and videos from Windows Explorer.

While I don't enjoy assigning blame, I still think this failure is contributed by both Microsoft and Apple. Microsoft failure is caused by the plug and play device driver installation module not doing the proper hardware detection and attempt to install generic driver that are persistent. Apple failure is it's failure to install driver installation properly. But I do sympathize the later for Apple developers are not *real* Windows developers, I think they could have done a better job at writing better software knowing that iOS devices are the current Apple's cash cow.

Saturday, May 5, 2012

SMB and Opportunistic Locking

Microsoft broke SMB backward compatibility again (sound of anguish!)

A friend of mine mentioned he cannot delete the file even after the application closed connection to a windows file server after the OS was upgraded and ask me if I seen such problem before. After some quick debugging, I have the following scenario:

App Server -> File Server -> DB Server

Application copies a temp file on File Share on File Server and App Server initiate a BCP from the File Server to a DB server. After the bcp job is completed, the application attempt to delete the temp file on File Share and failed because the file handles is still open, hence create an error condition. App Server running Windows 2003 creates the temp file on a Windows 2003 works. However, after the file server was upgraded to a Windows 2008-R2, the problem start occurring. App Server running Windows 2008-R2 creating the temp file on Windows 2008-R2 file share does not have that much problem.

So the problem is related to file locking and to better understanding the issue, we need to do a minimal post-mortem without attempting to use too much debugging tools with SysInternal tools or manually unlock a production server with unlocker tools. Since user runs a Windows file shares, I looked at how the SMB interacts with file locking, in particular the dependencies between SMB and oplocks to come with something we can justify about the failure. In the SMB protocol, opportunistic locking is a file locking mechanism designed to improve performance by controlling caching of network files by the client. Contrary to the traditional locks, OpLocks are not used in order to provide mutual exclusion. The main goal of OpLocks is to provide synchronization for caching.

To improve performance, Windows 2003 Server appear to only support SMB v1. By default, it enables and uses opportunistic file locking to allow multiple clients to read more database records than they currently need. This read-ahead can cause database corruption when multiple clients accessing the data, such as if one client modifies a record previously read by another client, then previous client may not flush the invalid data from the cache, hence create a possible database corruption. Microsoft recommends disabling opportunistic file locking in networks that clients writes to per KB296264.

The idea is that a client accessing a shared file can cache the file’s data for reuse without having to travel the network link multiple times; a classic caching technique. The only way the client can be sure that the cached file data hasn’t been changed is if the data gets locked out from writes by other clients. So the client places an "opportunistic lock" on the file, assuming the SMB server (the file server) approves the request – for example, if nobody else has the file open for writing. If another user subsequently wants to write to the file, the SMB server has to break the lock and then the original client is going to lose the speed benefit of caching the data locally.

With SMB v1, one can disable oplocks with a registry hack. There are situations in which they could create a net downgrade of performance and/or robustness, depending for example on the kind of database software you might be running. (Client/server databases might run faster and more happily with oplocks, but ISAM databases might run into data corruption issues.) However, you can’t turn oplocks off in SMB v2. Among other things, it would break the "offline files" feature if you did.

To disable opportunistic locking, you can modify the following registry entries:

Registry HiveValueTypeData
HKLM\SYSTEM\CurrentControlSet\Services\MRXSmb\ParametersOplocksDisabledREG_DWORD1
HKLM\SYSTEM\CurrentControlSet\Services\Lanmanworkstation\ParametersUseOpportunisticLockingREG_DWORD0
HKLM\SYSTEM\CurrentControlSet\Services\Lanmanserver\ParametersEnableOplocksREG_DWORD0

With SMB version 2.1, running on Server 2008 R2 and Windows 7, Microsoft has tuned the oplocks feature so that it works better in situations where a single application might generate multiple opens to the same file, which apparently happens more often. Microsoft claims a performance benefit from this tweak, providing yet another argument for giving serious thought to R2 and Windows 7.

My recommendation is user plan to use SMB 2.x only if they are running Windows 2008 machines on both ends. However, you can disable SMB 2.x entirely when one choose to run on different flavor OS version via modifying the registry setting disabling oplocks to work.

Saturday, April 28, 2012

Cloud computing 101

New technology often comes with new terminologies and often confusing so I did a quick research to understand the bigger picture of what cloud computing really offer us. Cloud computing itself is more than just accessing a blackbox somewhere in the Internet.

When you watch Microsoft advertisement "...to the cloud", this is form of IT delivery of computing requirements as a service to a heterogeneous community of end-recipients. In layman terms, one should start thinking cloud as a billable utility service delivery just like the power company provide electricity to their homes. Cloud providers offer these type of services based on 3 fundamental models.

  1. Infrastructure as a Service (IaaS) - The IaaS model is the most basic cloud service model. Cloud providers offer computing resources – as physical or more often as virtual machines, raw (block) storage, firewalls, load balancers, and networks. IaaS providers supply these resources on demand from their large pools installed in data centers. Local area networks including IP addresses are part of the offer. For the wide area connectivity, the Internet can be used or - in carrier clouds - dedicated virtual private networks can be configured. To deploy their applications, cloud users then install operating system images on the machines as well as their application software. In this model, it is the cloud user who is responsible for patching and maintaining the operating systems and application software. Cloud providers typically bill IaaS services on a utility computing basis, that is, cost will reflect the amount of resources allocated and consumed.
  2. Platform as a Service (PaaS) - In the PaaS model, cloud providers deliver a computing platform and/or solution stack typically including operating system, programming language execution environment, database, and web server. Application developers can develop and run their software solutions on a cloud platform without the cost and complexity of buying and managing the underlying hardware and software layers. With some PaaS offers, the underlying compute and storage resources scale automatically to match application demand such that the cloud user does not have to allocate resources manually. This is good choice for companies that have lots of tech resources and need to manage the applications.
  3. Software as a Service (SaaS) - In this SaaS mode, cloud providers install and operate application software in the cloud and cloud users access the software from cloud clients. The cloud users do not manage the cloud infrastructure and platform on which the application is running as these application are not install on user's own computer, thus reduce maintenance and support. Cloud application differs from other applications is its elasticity. This can be achieved by cloning tasks onto multiple virtual machines at run-time to meet the changing work demand. Load balancers distribute the work over the set of virtual machines. This process is transparent to the cloud user who sees only a single access point. To accommodate a large number of cloud users, cloud applications can be multitenant, that is, any machine serves more than one cloud user organization. It is common to refer to special types of cloud based application software with a similar naming convention: desktop as a service, business process as a service, Test Environment as a Service, communication as a service. The pricing model for SaaS applications is typically a monthly or yearly flat fee per user.
As a subscriber/customer to cloud service, cloud clients usually falls in one of the following deployment models.
  1. Public cloud - Public cloud applications, storage, and other resources are made available to the general public by a service provider. These services are free or offered on a pay-per-use model. Generally, public cloud service providers like Microsoft and Google own and operate the infrastructure and offer access only via Internet but user has to get their own direct internet/broadband connectivity separately.
  2. Community cloud - Community cloud shares infrastructure between several organizations from a specific community with common concerns (security, compliance, jurisdiction, etc.), whether managed internally or by a third-party and hosted internally or externally. The costs are spread over fewer users than a public cloud (but more than a private cloud), so only some of the cost savings potential of cloud computing are realized.
  3. Private cloud - Private cloud is cloud infrastructure operated solely for a single organization and could be managed internally or by a third-party. It is generally either hosted internally (private internal network) or externally (Internet) to only select users and not available to general public. They have attracted criticism because users "still have to buy, build, and manage them" and thus do not benefit from less hands-on management, essentially lacking the economic model that makes cloud computing such an intriguing concept.
  4. Hybrid cloud - Hybrid cloud is a composition of two or more clouds (private, community or public) that remain unique entities but are bound together, offering the benefits of multiple deployment models. By utilizing "hybrid cloud" architecture, companies and individuals are able to obtain degrees of fault tolerance combined with locally immediate usability without dependency on internet connectivity. Hybrid Cloud architecture requires both on-premises resources and off-site (remote) server based cloud infrastructure. Hybrid clouds lack the flexibility, security and certainty of in-house applications. Hybrid cloud provides the flexibility of in house applications with the fault tolerance and scalability of cloud based services.
There are few key terminology that one need to understand when approaching Cloud providers.
  1. Pay Per Use - A cost model for cloud services that includes both subscription-based and consumption-based models. This is in contrast to traditional IT models, which require capital expenditures along with hardware and software maintenance.
  2. Middleware – Middleware refers to software that sits between applications and operating systems, and enables them to talk to one another. An example would be a program that would allow your SAP system to talk to your Internet fax provider.
  3. Elasticity – This allows cloud customers to experience rapid scaling of applications and usage without the need to build out infrastructure or deploy internal resources. Peak periods can be met, while needs for lesser capacity are met without unnecessary overhead, eliminating the need for capacity planning and simplifying budgeting.
  4. Availability – One advantage of using a cloud provider is knowing that the scale they bring to the table ensures that the services you require are available when and where you need them. With network and process assets served across multiple environments and locations, you greatly increase resource and application availability.
  5. SLA – An important item to consider when working with outside cloud vendors are Service Level Agreements, or SLA’s. These agreements are key to knowing that the level of service you are expecting is agreed upon in writing by your service provider. One should always question and access the acceptable risks since the cloud provider's SLAs are also a method for them to offload their liability to their customers.